Link to generic _Document returns undefined _meta

I have a Link field in a Slice that can link to anything, i.e. external sites, media files and any document type in our repository. Within my query, the Link is defined as follows:

...
          link {
            __typename
            ... on _ExternalLink {
              url
            }
            ... on _FileLink {
              url
            }
            ... on _Document {
              _meta {
                type
                id
                uid     
              }
            }
          }
...

If the link field points to a document and I query using the GraphiQL UI, I get the results I expect-- the _meta sub-field is populated:

...
            "link": {
              "__typename": "Resource",
              "_meta": {
                "type": "resource",
                "id": "YSkXJxAAACIA_F_t",
                "uid": "example-resource"
              }
            }
...

However, in my application, when I query using Apollo, the resulting _meta field is undefined.

I really hope there is an alternative to explicitly enumerate all of our repos document types on every query. Given our large number of custom types and affected queries, it would be a pain to maintain and really blow up the size of our queries.

Thanks for the help!

Hey @jeremy2, thanks for reaching out!
Could you share with us an example of the query you're making?
I'd like to reproduce it on my end.

For link fields that cover all of the cases, as you've already mentioned (External links, files, and documents), it is necessary to explicitly tell the link field which one of them it's expecting.

An alternative could be to create a Link field that is dedicated to each use case. For example, add a Content Relationship field to be the one that handles all internal links.

Thanks, @Pau.

Here's a query:

query GetResourcePage($uid: String!) {
  resource_page(uid: $uid, lang: "en-us") {
    body {
      ... on Resource_pageBodyLink_button {
        type
        primary {
          button_title
          link {
            __typename
            _linkType
            ... on _ExternalLink {
              url
            }
            ... on _ImageLink {
              url
            }
            ... on _FileLink {
              url
            }
            ... on _Document {
              _meta {
                type
                id
                uid
              }
            }
          }
        }
      }
    }
  }
}

And the vars:

{
  "uid": "link-test"
}

Results from GraphiQL:

{
  "data": {
    "resource_page": {
      "body": [
        {
          "type": "link_button",
          "primary": {
            "button_title": "Open Document",
            "link": {
              "__typename": "Resource_page",
              "_linkType": "Link.document",
              "_meta": {
                "type": "resource_page",
                "id": "YCVhMhUAACYAt98c",
                "uid": "demo-resource-page"
              }
            }
          }
        },
        {
          "type": "link_button",
          "primary": {
            "button_title": "Open Media Item",
            "link": {
              "__typename": "_ImageLink",
              "_linkType": "Link.image",
              "url": "https://images.prismic.io/mycep-content/e0c832d5-13c9-46d7-a85f-85bcba9b2a31_ga-exercise-squat.jpg?auto=compress,format"
            }
          }
        },
        {
          "type": "link_button",
          "primary": {
            "button_title": "Open Web",
            "link": {
              "__typename": "_ExternalLink",
              "_linkType": "Link.web",
              "url": "http://endless.horse/"
            }
          }
        }
      ]
    }
  }
}

But the results from Apollo, the _meta field on the `_Document' link is undefined.

I'll send our repo ID in a PM, if you would like to query directly against our repo.

Thanks for the assistance!

Hey there @jeremy2.

I ran a test on your repository using apollo and returned the meta object of the linked doc without any problem. Sometimes links to docs fail when the link is broken because the document has been archived or deleted. Could this be the case?

This thread has been closed due to inactivity. Flag to reopen.