GraphQL query by date and filter parameters in Admin API

Shopify Partner
16 0 6

Congratulations on launching GraphQL for the Admin API. I was wondering if you could give an example on how to use filter parameters in the query argument, eg for orders. I know it expects a String, but I don't know the actual format to use.

query {
  orders(first: 10, query: "string here") {
    edges {
      cursor
      node {
        id
        name
        lineItems(first: 3) {
          edges {
              cursor
              node {
              name
              image {
                id
                originalSrc
              }
            }
          }
        }
      }
    }
    
    pageInfo {
      hasNextPage
    }
  }
}

Also, is there a way to construct a query that allows the use of operators? My use case is getting orders since a particular created_at parameter, so my pseudo approach would look something like this:

query {
  products(first: 1, reverse:false, query: { created_at: { gt: "2018-04-01"} }) {
    edges {
      node {
        title
        createdAt
        productType
        collections(first:2) {
          edges {
            node {
              handle
            }
          }
        }
        
      }
    }
  }
}

If there is a way to do this with the current schema, I'd appreciate some tips!

Kind regards,

Michael

3 Likes
Shopify Partner
1 0 0

hey Michael, was just looking for the same thing, and I found this post helpful:
https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/syntax-for-query-argument-in-graphql-s...

basically the syntax looks like this:

products(first:10, query:"product_type:'Men' title:'My product'")

 

 

0 Likes
Highlighted
Shopify Partner
16 0 6

Thanks! I never had to use the Storefront API, so this is very helpful info and at least gives me the format.

Using created_at is not very useful if all I can do is an exact match where I have to pass the exact timestamp. Still think and hope that it will be a very common and logical use case to have the ability to pass a date a date and fetch results after or before that date, not just the exact timestamp.

orders(first: 3, reverse:false, query:"created_at='2015-03-17T19:30:46Z'")

// want all results after that date, not just at that particular time

 

1 Like
Shopify Partner
2 0 2

Would it be possible for you guys to add the same behavior as created_at_min and created_at_max that exist in the REST API endpoints? That's the kind of feature we really need to build faster queries.

Thanks!

2 Likes
New Member
1 0 1

I'll second the need for created_at_min and created_at_max (and equivalent for updated_at) as necessary to make the graphql connections (like orders) useful in practice.

1 Like
Shopify Partner
7 0 0

Is it Possible to query orders by tag?

0 Likes
New Member
2 0 0

It still doesn't look like min and max date values have been added to the GraphQL query string parameter yet.

0 Likes
New Member
2 0 6

@jsells wrote:

Is it Possible to query orders by tag?



This is possible: 

orders(first: 10, query: "fulfillment_status:unshipped,tag: 'myTagHere'")
0 Likes
Shopify Partner
21 0 3

Hey @Michael_Whitak1 ,

 

This is really not obvious when reading the docs. However, this should work.

 

{
  orders(query:"created_at:>2019-04-04", first:10) {
    edges {
      node {
        id,
        name,
        createdAt
      }
    }
  }
}

Hope it helps. 

Founder of Evermark - Smart and automated Facebook ads for your Shopify store.
1 Like