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!