Express server not passing Shopify 'extensions' object back to app in GraphQL response

Express server not passing Shopify 'extensions' object back to app in GraphQL response

Danh11
Shopify Partner
84 2 38

I have a Shopify/React app which is using Express (cloned from Shopify/shopify-app-node). I'm able to successfully make GraphQL calls to the admin API and receive the data back as expected, however, I'm also wanting to retrieve the extensions object with the information on the cost and budget of the query.

 

This is the Express route where I'm also logging the response:

 

  app.post("/graphql", verifyRequest(app), async (req, res) => {
    try {
      const response = await Shopify.Utils.graphqlProxy(req, res);
      
      console.log('response.body:', response.body)

      res.status(200).send(response.body);
    } catch (error) {
      res.status(500).send(error.message);
    }
  });

 

 

This is my query within the app:

 

  apolloClient.query({
    query: GqlProducts,
    variables: { count: 10 },
    context: { headers: { "X-GraphQL-Cost-Include-Fields": true } }
  })
  .then( response => console.log('response:', response) )
  .catch( error => console.log(error) )

 

 

*I'm not using the typical Apollo useQuery hook as this is inside a helper function. Instead, I'm passing useApolloClient() down as apolloClient to make the request.

 

 I can see both data and extensions objects when I log the response within the server. This is the response in the terminal window where the server is running: 

 

response.body: {
  data: {
    products: {
      pageInfo: [Object],
      edges: [Array],
      __typename: 'ProductConnection'
    }
  },
  extensions: {
    cost: {
      requestedQueryCost: 192,
      actualQueryCost: 53,
      throttleStatus: [Object]
    }
  }
}

 

 

However, the extensions object does not seem to be available within the app. I only receive the data object. This is the response in the browser console:

 

response: 
{data: {…}, loading: false, networkStatus: 7}
    data:
        products: {__typename: 'ProductConnection', pageInfo: {…}, edges: Array(10)}
        [[Prototype]]: Object
    loading: false
    networkStatus: 7
    [[Prototype]]: Object

 

 

Is there something that I am missing for this object to be available?

Replies 0 (0)