Query all custom types when using internal links

Hello,

I'm having a hard time understanding why we need to query all possible linked custom types using GraphQL fragments in order to retrieve a linked page's uid and lang.

Here's an example:

demo_link {
          ... on PRISMIC__FileLink {
            url
          }
          ... on PRISMIC__ExternalLink {
            url
          }
          ... on PRISMIC__ImageLink {
            url
          }
          ... on PRISMIC_Clients {
            _meta {
              uid
              lang
              type
            }
          }
          ... on PRISMIC_Content_landing_page {
            _meta {
              uid
              lang
              type
            }
          }
          ... on PRISMIC_Demo {
            _meta {
              uid
              lang
              type
            }
          }
          ... on PRISMIC_Home {
            _meta {
              uid
              lang
              type
            }
          }
          ... on PRISMIC_Landing_page {
            _meta {
              uid
              lang
              type
            }
          }
          ... on PRISMIC_Partners {
            _meta {
              uid
              lang
              type
            }
          }
          ... on PRISMIC_Press {
            _meta {
              uid
              lang
              type
            }
          }
         ...

This is resulting in extremely long GraphQL queries in our projecs (using over 30 custom types). Some of our queries are over 800 lines, just because of this limitation, making our queries unreadable.

Isn't there a way to do something like the following instead?

demo_link {
          ... on PRISMIC__All {
            _meta {
              uid
              lang
              type
            }
          }

Thank you,
Nicolas

1 Like

That’s a ‘feature’ of GraphQL, unfortunately. Have you tried the REST API?

No we haven’t because we’re using the gatsby-source-prismic-graphql plugin.

Would switching over to the gatsby-source-prismic plugin change this behavior? I understand that this might become the officially supported source plugin for Gatsby in the near future.

It looks like that one uses graphql too, in which case you have the same situation.


EDIT:

You may want to look at this section: Query Link Fields:

Link fields are processed using the official prismic-dom library and the linkResolver function from your site’s gatsby-config.js . The resolved URL is provided at the url field.

If the link type is a web link (i.e. a URL external from your site), the URL is provided without additional processing.

All other URL fields, such as target , lang , and isBroken , are provided on the field, as well.

The target field defaults to an empty string. This allows you to always query the target field even if it is not set in Prismic.

Note : If you need to access the raw data, the original data is accessible using the raw field, though use of this field is discouraged.

{
  allPrismicPage {
    edges {
      node {
        id
        data {
          featured_post {
            url
            target
          }
        }
      }
    }
  }
}

This issue has been closed due to inactivity.