Cannot get graphql data as Unexpected end of JSON input

Melonendk
New Member
8 0 0

So i im working with apollo client to fetching and mutateing data from shopify sometimes it works and sometimes it wont, in the end i always get the error

Unexpected end of JSON input

which is weird because it have worked and i honeste been trying for days to figure it out.

I've followed apollos guide on getting started aswell as using their method to set custom header to get access but honestly i dont know anymore

I have also tested the query on shopify's own graphql tester and it works.

But as you can see under here everythigs seems correct, what am i missing what have a done wrong ?

client.js

 

 

import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client';
import { setContext } from '@apollo/client/link/context';

const httpLink = createHttpLink({
  uri: `https://${process.env.SHOPIFY_SHOP}.myshopify.com/admin/api/${process.env.SHOPIFY_API_VERSION}/graphql.json`,
});

const headsLink = setContext((_, { headers }) => ({
  headers: {
    ...headers,
    'X-Shopify-Access-Token': process.env.SHOPIFY_API_SECRET,
    'Content-Type': 'application/graphql',
  },
}));

const client = new ApolloClient({
  link: headsLink.concat(httpLink),
  cache: new InMemoryCache()
});

export default client

 

 

 fetchProduct.js

 

 

// sku is specified via a const earlier that is a string
const GET_PRODUCT = gql`
  query {
    inventoryItems(first:1, query:"sku:${sku}") {
      edges {
        node {
          id
          sku
          variant {
            id
            title
            displayName
          }
        }
      }
    }
  }
`;
const shopProduct = await client.query({
  query: GET_PRODUCT,
}).catch((e) => console.log(e));

 

 

 

In this case where apollo might failing me what alternative is there you can recommend?

Replies 0 (0)