Shop ID graphQL query returning no data

Solved

Shop ID graphQL query returning no data

SomeUsernameHe
Shopify Partner
495 54 99

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. 

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee
Accepted Solution (1)

SBD_
Shopify Staff
1829 271 414

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 

View solution in original post

Replies 2 (2)

SBD_
Shopify Staff
1829 271 414

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 

SomeUsernameHe
Shopify Partner
495 54 99

Yup, apparently I am blind lol. Thank you!

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee