Skip to content

Craft CMS 5 – LinkIt GraphQL returns null for Link fields inside Matrix blocks #120

Description

@a-am

Plugin version: 5.0.0
Craft CMS version: 5.8.22
PHP version: 8.2

Problem

When querying a LinkIt field inside a Matrix block via GraphQL, the field resolves incorrectly:

  • The LinkIt field itself (contactDetails) resolves to an object
  • All subfields (link, url, label, type, etc.) return null
  • In some cases, the resolver receives an empty craft\elements\ElementCollection instead of a presseddigital\linkit\base\Link model

The same LinkIt field works correctly outside of Matrix and works fine in Twig.

Expected Behavior

A LinkIt field inside a Matrix block should resolve via GraphQL the same way it does on an Entry:

contactDetails {
  link
  url
  label
  type
  typeHandle
  text
}

…returning the actual link values.

Actual Behavior

GQL Response

{
  "contactDetails": {
    "link": null,
    "label": null,
    "url": null,
    "typeHandle": null,
    "type": null,
    "text": null
  }
}

In debugging, the GraphQL resolver often receives:

craft\elements\ElementCollection {
  items: []
}

instead of a presseddigital\linkit\base\Link instance.

Reproducing Steps

  1. Create a Matrix field with a block type containing a LinkIt field
  2. Add content to that LinkIt field
  3. Query via GraphQL:
{
  entries(section: "officeLocations") {
    ... on officeLocations_Entry {
      contactLinks {
        ... on contactLink_Entry {
          contactDetails {
            link
            label
            url
            type
            typeHandle
            text
          }
        }
      }
    }
  }
}
  1. Observe that all contactDetails subfields return null

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions