Error when trying to create a dynamic query using Gatsby + Sanity
17 replies
Last updated: Feb 4, 2022
C
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
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.
fetchor
axiosbut I'm getting the following error
"description": "expected '}' following object body",
Feb 4, 2022, 9:26 PM
C
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 devon your front end.
Feb 4, 2022, 9:37 PM
C
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
C
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
C
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
C
yes
Feb 4, 2022, 9:47 PM
C
yes
Feb 4, 2022, 9:47 PM
C
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
If you go to that URL, you should be able to try your queries.
In your terminal, if you run
sanity graphql deploy --playgroundin 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>
Feb 4, 2022, 9:51 PM
C
ahhh OK, I will give it a shot
Feb 4, 2022, 9:52 PM
C
ahhh OK, I will give it a shot
Feb 4, 2022, 9:52 PM
C
Got it! Thanks a lot for the help
Feb 4, 2022, 9:54 PM
C
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
C
OK, gotcha. Thanks again!
Feb 4, 2022, 10:05 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.