A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
export async function loader({ request, params }) {
try {
const { admin, session } = await authenticate.admin(request);
const queryString = `query {
products () {
edges {
node {
id
title
}
}
}
}`
const response = await admin.graphql({
data: queryString
})
} catch (error) {
console.error("Authentication or GraphQL error:", error);
}
I am trying to get products with GraphQL and getting the following error. I am using the Shopify CLI, I tried to follow everything in the tutorial, but I spent 6 hours trying to solve this issue. Please help! LOL.
This is my configuration:
Hi Oozbasaran,
Can you check to make sure that your access token is valid? If you're unsure, you can regenerate a new token and replace it in your code.
Another option to troubleshoot would be to run the same query in the Shopify GraphiQL app to see if it's working there. Depending on if it works or not you can try to rule out what's causing this.
Hope this helps,
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
My shopify.server.js file is like the above. Does not it handle the Auth automatically?
The query is working in the Shopify GraphQL app, but not in my code, I tried a mutation and it is working in my code, but not the query.
Been doing a bit more digging myself, in the shopify.server.js file it's referencing process.env, so I think we may need save the token in an env file somewhere; however, some of these values seem to be automatically set in the shopify.app.toml file
This however, is still giving me a 400 error
I'm having the same error:
In an app set up with Shopify CLI, a simple graphql query (near identical format to OP) is returning a 400.
This set up seems to match the docs, so any input on how to get a simple query running in a shopify app would be a huge help.
Thanks!
Hi there! I played around with this some more and ultimately found that the issue was with my query string. This ended up working for me:
`#graphql
query getProducts{
products(first: 10, reverse: true) {
edges {
node {
id
title
handle
images(first: 1) {
edges {
node {
originalSrc
}
}
}
variants(first: 1) {
edges {
node {
price
selectedOptions {
name
value
}
}
}
}
}
}
}
}`
Great to hear this is working for you! Thanks for posting up your solution!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog