GraphQL type names are different in GraphiQL editor than what is needed for GraphQuery

I am trying to figure out the most reasonable way to build large graphQueries. The autocompletion in the GraphiQL editor (e.g. Graphql - Prismic) is extremely helpful for this. Unfortunately, in specific cases such as requesting data for Slices or Content Relationship Links, the query necessary for graphQuery is different from what is created in GraphiQL.

For example, if you create a query in the GraphiQL Editor that requests data from a page with slices, it might look something like this:

{
  blog_post(uid: "my-id", lang: "en-us") {
    title
    slices {
      ... on Blog_postSlicesMy_slice {
        variation {
          ...on Blog_postSlicesMy_sliceDefault {
            primary {
              text
            }
          }
        }
      }
    }
  }
}

But if you pass this to graphQuery, you will get an error. Instead you would need this:

{
  blog_post {
    title
    slices {
      ...on my_slice {
        variation {
          ...on default {
            primary {
              text
            }
          }
        }
      }
    }
  }
}

So as you can see the type names are different (Blog_postSlicesMy_slice vs my_slice ).

If you need all the data from a document, but also need to get the data from a Content Relationship Link, then you're forced to use graphQuery, which means you need to type out a giant query with all the fields for multiple documents/type/slices/variations, and on top of that you need to fix a bunch of incorrect type names without making any typos.

Is there any better way to create these queries than building the incorrect version in GraphiQL and then carefully editing it?


I didn't mean for this to be a feature request, but now that I think about it, it would potentially be a nice feature in SliceMachine if it could give you a snippet of a query that requests all the data for a type. It would be a lot easier to start with a full query and delete the fields you don't need, than to build it from scratch in GraphiQL.

I appreciate any suggestions anyone has for making this process more pleasant. Thanks!

Hi @travis.travis,

Thanks for reaching out about this, and I completely understand how this isn't an ideal workflow. Yes, it's true that GraphQuery uses a GraphQL-like syntax, but isn't completely the same thing. If you use the GraphiQL editor to build it, then you're right that you'll need to update certain values to make it work with GraphQuery.

I know that the dev team is considering changing the way you fetch content through a content relationship field. So hopefully at some point in the future this will all be much easier.

For now, I would say you're on the right track with how you're building your queries. I'll submit your feature request to the team as I agree it would make things easier if there was some sort of GraphQuery editor in Slice Machine.

Let me know if you have any other questions about this or anything else.

1 Like