Syntax for "query" argument in GraphQL (Storefront API)

Highlighted
Shopify Partner
18 0 5

Hello guys, I'm wondering what's the syntax we should use for the "query" argument many of the Objects offer. The documentarion say "String" and passing for example "Accessories" to find Products in the "Accessories" collection works. But it feels a little loose. Is there a way to make it more explicit that I'm only searching for collections called "Accessories"?

This was just an example, any information on the topic will contribute a lot! Thanks!

1 Like
Shopify Partner
11 0 1

I'm looking for the same information myself.  

You can do exact matching - e.g.

query:"title='My Title'"

I've not figured out how to do partial matches, so for me it is less useful than not providing the field but it might be what you are after.

 

 

 

1 Like
Shopify Partner
18 0 5

Thanks for replying! That's a confusing feature because it only seems to work in some cases. For example, if I do:

products(first: 10, query: "title='Verma'")

It works, but if I do:

products(first: 10, query: "product_type='Men'")

It does not work even though the documentation says "product_type" is supported as a filter in the query argument.

Do you see anything I might be doing wrong here?

Cheers!

1 Like
New Member
1 0 1

I've not managed to get any of the other filters working either..  

 

It would be really helpful for some at Shopify to help explain how to use it. 

1 Like
Shopify Partner
18 0 5

Just got a reply from a staff at Shopify and from his response and my tests I understood that you can do things like:

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

or

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

There has to be no space between the colon and the value queried, and there is no comma between parameters. Also, it's case insensitive. 

2 Likes
Shopify Partner
11 0 1

Great!  That helps.    Was there any info on how to do partial matches?

0 Likes
Shopify Partner
18 0 5

Unfortunately our guy didn't say much cause he himself didn't have a lot of experience with this API. I'm hoping we'll see more developments on it soon as it's a killer feature on Shopify's tool belt :)

0 Likes
New Member
8 0 0

Hi,

I need to filter product list but getting this error after passing parameter in product

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

Error Message

 "message": "Field 'products' doesn't accept argument 'query'"

 

Please suggest

0 Likes
Shopify Partner
14 0 3

So, this is a bit of a mess. And believe it or not, this thread is currently the best documentation on how to use the query field.

@Shopify, please help us out here as we're currently doing guesswork.

 

Here's what I know so far:

While you can see what query fields are claimed to be supported here (https://help.shopify.com/en/api/graphql-admin-api/reference/queryroot) it is actually not accurate. Only some of those fields are in practice supported. But, some actually do work.

I'm currently working on orders() and for this it seems that the status of the working/non-working query fields are:

- email: not working

- status: not working?

- fulfillment_status: IS WORKING

- customer_id: IS WORKING

When running queries, the correct format is this:

orders(first:3, query:"customer_id:871660388411")

The incorrect format is this (incorrectly claimed to be correct in a previous post):

orders(first:3, query:"customer_id=871660388411")

(e.g. do not use '=' but instead ':'

It seems that the query field is insensitive to extra quotations for at least numbers. The following does work:

orders(first:3, query:"customer_id:'871660388411'")

It is also insensitive to left out quotations for strings.

 

I hope this helps someone out there trying to get this working despite of Shopify's complete lack of documentation and support for the community.

 

1 Like
Community Manager
Community Manager
336 17 75

Have you seen this doc: https://help.shopify.com/en/api/getting-started/search-syntax

Developer Experience @ Shopify
0 Likes