Re: blocked by CORS when accessing the Cart graphQL query root

blocked by CORS when accessing the Cart graphQL query root

alexdeveloper
Shopify Partner
1 0 2

I've just migrated from the Checkout queryroot to the Cart queryroot.

For some reason, only queries accessing this Cart queryroot are blocked, and a 500 error is logged:

 

Access to XMLHttpRequest at 'https://XXX.myshopify.com/api/2022-10/graphql.json' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

Queries to other areas like Products and Collections function and fetch the relevant data.

GraphQL endpoint: 

 
Cart Query:
query getCartItemCount($cartId: ID!) {
  node(id: $cartId) {
    ... on Cart {
      __typename
      lines(first: 250) {
        nodes {
          quantity
        }
      }
    }
  }
}


Building on NextJS, this occurs on localhost & a deployed instance with HTTPS.

Please help!

Reply 1 (1)

dimasidor3nk0
Shopify Partner
1 0 0

It's an old question, but I recently got the same issue and couldn't find the answer. It is frustrating.

I finally solved it. Maybe it will be helpful for someone else.

In my case the issue was that when I migrated from Checkout to Cart I used a `node` query like for Checkout:

 

query Cart(
  $id: ID!
) {
  cart: node(id: $id) {
    ... on Cart {
      ...CartFragment
    }
  }
}

 

When I changed it to a `cart` query the error is gone.

 

query Cart(
  $id: ID!
) {
  cart(id: $id) {
      ...CartFragment
  }
}