Solved

Why do you need a "first" or "last" field if you're using both "before" and "after"?

jlarks32
Visitor
3 0 0

I am trying to use GraphQL to retrieve various information about my orders. My GraphQL schema basically looks like this:

query order {
  orders(before: "2021-11-02", after: "2021-01-01") {
    edges {
      node {
        app {
          name
        }

 
But I am getting the following error: 

you must provide one of first or last

 

Why is this and how can I get around it? I just want my search results to be filtered by a date period rather than a set count that I have to enforce.

Accepted Solution (1)

csam
Shopify Staff (Retired)
267 40 51

This is an accepted solution.

Hi @jlarks32 

The before and after parameters limit the range of results, whereas the first/last parameter determines how many results from that range to return at a time, and whether to start at the beginning of the set or the end. This is needed if you're going to paginate through results. Imagine that you have 1500 orders during the 11 month period that you're querying. You can't return all 1500 orders in a single response, so you need to specify how many orders to return at a time, and whether to start with oldest first or newest first. You can read more about how this works in our GraphQL documentation and there is also a post on the partners blog with accompanying video here: https://www.shopify.ca/partners/blog/graphql-pagination

Best,

 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Reply 1 (1)

csam
Shopify Staff (Retired)
267 40 51

This is an accepted solution.

Hi @jlarks32 

The before and after parameters limit the range of results, whereas the first/last parameter determines how many results from that range to return at a time, and whether to start at the beginning of the set or the end. This is needed if you're going to paginate through results. Imagine that you have 1500 orders during the 11 month period that you're querying. You can't return all 1500 orders in a single response, so you need to specify how many orders to return at a time, and whether to start with oldest first or newest first. You can read more about how this works in our GraphQL documentation and there is also a post on the partners blog with accompanying video here: https://www.shopify.ca/partners/blog/graphql-pagination

Best,

 

To learn more visit the Shopify Help Center or the Community Blog.