'How to retrieve Shopify's 'extensions' object in GraphQL response for query cost data

I have a React app that I have cloned from the shopify-app-node repo (the latest version using Express). I'm making GraphQL calls to Shopify's Admin API and I would like to also return cost information. I understand that there is an extensions object that contains this information but it is not returned in a typical GraphQL call. I have attempted to read and understand the documentation of Shopify/shopify-node-api but Shopify's current version of their React app doesn't reflect what the documentation states. Not in a way I can understand anyway.

This is the route defined when the server is initiated:

app.post("/graphql", verifyRequest(app), async (req, res) => {
    try {
      const response = await Shopify.Utils.graphqlProxy(req, res);
      res.status(200).send(response.body);
    } catch (error) {
      res.status(500).send(error.message);
    }
  }); 

And then I make the query with the following: (apolloClient is being passed down from the parent component as this is a helper function and useQuery won't work due to it being a hook.

const apolloClient = useApolloClient();
    
apolloClient.query({
    query: GqlProducts,
    variables: {
        count: 10
    }
})
.then( response => {
    console.log(response.data);
    console.log(response.extensions);
})
.catch( error => console.log(error) )

Obviously I get an undefined on response.extensions.

Along with any hints or suggestions on how to get this working, I'm also curious to know why it's not returned in a typical response.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source