Error when trying to create a dynamic query using Gatsby + Sanity

17 replies
Last updated: Feb 4, 2022
Hello, I'm using Gatsby + Sanity and the Gatsby static GraphQL queries have been working great. I am now trying to create a dynamic query using
fetch
or
axios
but I'm getting the following error
"description": "expected '}' following object body",
returned with a 400 status code. I'm using the same query that was a static query before. I've even tried using an external tool and the Vision tool with the same results.
Feb 4, 2022, 9:26 PM
I'm guessing I'm just doing it wrong, but my URL appears correct and, like I said, my query is unchanged
Feb 4, 2022, 9:27 PM
The Vision plugin can only handle GROQ queries. For GraphQL queries, you can use the playground (if you request one when you deploy your GraphQL API) or in GraphiQL, which I believe will live on localhost:8000 when you run
npm run dev
on your front end.
Feb 4, 2022, 9:37 PM
OK, that makes sense. I still have the same problem in tools like Insomnia or even in my app
Feb 4, 2022, 9:39 PM
OK, that makes sense. I still have the same problem in tools like Insomnia or even in my app
Feb 4, 2022, 9:39 PM
From Insomnia
Feb 4, 2022, 9:39 PM
Is your URL in Insomnia something like
<https://PROJECT_ID.api.sanity.io/v2021-03-25/data/query/dev?query=>…
?
Feb 4, 2022, 9:41 PM
Is your URL in Insomnia something like
<https://PROJECT_ID.api.sanity.io/v2021-03-25/data/query/dev?query=>…
?
Feb 4, 2022, 9:41 PM
yes
Feb 4, 2022, 9:47 PM
yes
Feb 4, 2022, 9:47 PM
Is that a GROQ specific url?
Feb 4, 2022, 9:48 PM
It is. Behind the scenes, we actually convert GraphQL queries to GROQ.
In your terminal, if you run
sanity graphql deploy --playground
in your studio folder you should get a URL at the end of the output, like this (as long as everything succeeds):

GraphQL API deployed to:
<https://PROJECT_ID.api.sanity.io/v1/graphql/dev/default>
If you go to that URL, you should be able to try your queries.
Feb 4, 2022, 9:51 PM
ahhh OK, I will give it a shot
Feb 4, 2022, 9:52 PM
ahhh OK, I will give it a shot
Feb 4, 2022, 9:52 PM
Got it! Thanks a lot for the help
Feb 4, 2022, 9:54 PM
I also need to remove the edges/node stuff. Is that also GROQ-related?
Feb 4, 2022, 9:54 PM
I think that’s because you’re in GraphQL Playground , which lets you test queries a bit more easily. I’m fairly sure you’ll still need your nodes/edges when you’re testing in GraphiQL (on your front end) and writing your queries in Gatsby.
Feb 4, 2022, 10:04 PM
OK, gotcha. Thanks again!
Feb 4, 2022, 10:05 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?