A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am having an issue querying the shop ID. I have simplified my code to the bare minimum and yet I am still getting no data back from my response.
Here is my GraphQL query:
const shopQuery = `query { shop { id } }`;
Which works perfectly in GraphiQL, but when I try to use it in my remix app, I get the following response:
21:20:44 │ remix │ Complete Response: { 21:20:44 │ remix │ "size": 0 21:20:44 │ remix │ }
here is the MCVE code:
import { json } from '@remix-run/node'; import { authenticate } from '../shopify.server'; // Adjust the path to your shopify.server file export const action = async ({ request }) => { const { admin } = await authenticate.admin(request); // GraphQL query to fetch the shop ID const shopQuery = `query { shop { id } }`; try { // Perform the GraphQL query to fetch the shop ID const response = await admin.graphql(shopQuery); // Log the response to see the shop ID console.log("Complete Response:", JSON.stringify(response, null, 2)); // Return a success response with the shop ID for debugging return json({ success: true, shopId: response.data.shop.id }); } catch (error) { // Log and return the error console.error('Error fetching shop ID:', error); return json({ error: error.message }, { status: 500 }); } };
Any help would be greatly appreciated.
Solved! Go to the solution
This is an accepted solution.
Hey @SomeUsernameHe
I think you might need to await the `.json()` . E.g.:
const response = await admin.graphql(`
{
shop {
id
}
}`);
const {
data: {
shop
},
} = await response.json();
Scott | Developer Advocate @ Shopify
This is an accepted solution.
Hey @SomeUsernameHe
I think you might need to await the `.json()` . E.g.:
const response = await admin.graphql(`
{
shop {
id
}
}`);
const {
data: {
shop
},
} = await response.json();
Scott | Developer Advocate @ Shopify
Yup, apparently I am blind lol. Thank you!