Help with Variables in a Graphql Request

Highlighted
Tourist
7 1 1

Hi Everyone,

I'm new to developing shopify apps and graphql.

I'm trying to query shopify's admin graphql, similar to this guide: https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/fetch-data-with-apollo . For those unfamiliar, we are using Apollo Client in the front-end and proxying the request to the backend.

I have create the request I wanted in the shopify GraphiQL tool (see below).  I'm trying to request on all orders between two dates.

 
 

Screenshot from 2020-07-19 20-32-28.png

I'm trying to make the same request in my code (below).  However when the app loads I get this error: 

 

 

GraphQL error: Variable $startTime is declared by getOrders but not used GraphQL error: Variable $endTime is declared by getOrders but not used

 

 

 

Screenshot from 2020-07-19 20-33-19.png

Wondering if anyone knows how to make this request work and where are the best resources for help on this in the future?

There might be a way better way of fetching this data, so if you know of an easier way, I'd be intrigued to learn.

 

From a new shopify dev perspective: Shopify documentation is lacking when it comes to using graphql vs REST implementations, (ie when should I use one over the other, confusing).  Also, online I'm finding that the Apollo library I'm using (which is also used in the guide linked above) is deprecated https://www.apollographql.com/docs/react/api/react/components/ .  Not sure if this should be reflected in the guide

Thanks.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
7 0 1

Hi @akatcha,

GraphQL doesn't allow you to use variables as part of a string within a query, so you won't be able to use $startTime and $endTime inside your query that way.

One possible solution for this would be to define your query as query getOrders($query: String!) and pass in a formed query created_at:>... created_at:<..., and build that query in your app code before going into GraphQL.

Also, thank you for your feedback on the guide, it's very helpful!

Hope this helps!

1 Like