I’m building off the Shopify CLI Node + React starter app using App Bridge and Apollo to do GraphQL queries.
No matter what I try, I get 400 bad request.
I have no problems querying the REST Admin API and receiving responses.
But when I try to use GraphQL, it’s always 400 bad request.
Just like the ProductsCard component in the starter app built by Shopify CLI, I’ve created an OrdersCard component which I want to use to display the most recent 5 orders (later I will be filtering for a specific cart attribute, but for now, I am just trying to get this working, so keeping the query simple.
Here’s the code in my ProductsCard component:
const ORDERS_QUERY = gql`
query getOrders {
orders {
edges {
node {
id
}
}
}
}
`;
const { loading, error, data, refetch } = useQuery(ORDERS_QUERY);
if (loading) {
console.log('loading...');
return
In App.jsx, I'm using the default ApolloProvider setup built by the Shopify CLI:
```javascript
function MyProvider({ children }) {
const app = useAppBridge();
// getSessionToken(app).then(token => {
// console.log('getSessionToken result: ', token)
// });
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
credentials: "include",
fetch: userLoggedInFetch(app),
// headers: {
// 'Content-Type': 'application/graphql',
// },
}),
});
return ;
Finally, here’s what App function returns in App.jsx, so as you can see, MyProvider is wrapped around any page content: