Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

admin graphql query filter not working for inner nodes

Solved

admin graphql query filter not working for inner nodes

lounik
New Member
4 0 0

Hi,


I have the following query that gives me all the companies currently in my shop (I limited to 10 for testing purposes): 

{
companies (first:10) {
edges {
node {
name
contacts (first:2) {
nodes {
customer {
email
}
}
}
locations (first:2) {
nodes {
staffMemberAssignment(first:2) {
nodes {
staffMember {
email
}
}
}
}
}
}
}
}
}

 

If I want to filter the companies by companies direct attribute (eg: name): 

companies (first:10 query:"name:'MY COMPANY NAME'") {
...
}

 the filter works as expected, I get one result, which is the company data with the name written in the query filter. 

 

However, the query filter doesn't work if I try to filter the companies list by any inner node (eg: customer email):

companies (first:10 query:"contacts.customer.email:'customer@email.com'") {
...
}

 This query gets ignored, and I get the list of all the companies instead. 

 

I looked at the documentation but all the example given for queries reguards the direct nodes, there is nothing about filtering by connected nodes.

 

Is there a way to filter the list by an inner node (such as customer email)?

 

Accepted Solution (1)

SomeUsernameHe
Shopify Partner
519 58 111

This is an accepted solution.

Currently, Shopify's GraphQL Admin API does not support filtering by inner nodes or nested fields (like contacts.customer.email) directly in queries. Filtering works well for top-level attributes like name (e.g., companies(first:10, query:"name:'My Company Name'")), but when trying to filter by nested fields (e.g., contacts.customer.email), the API ignores the query filter and returns all results.

This limitation arises because Shopify's query argument is designed to filter based only on direct attributes of the object being queried. While this works for simple filters on top-level fields, it doesn't extend to related fields within nested objects such as contacts or locations. As of now, there is no direct support for querying on inner nodes like customer emails or staff member emails in the current Shopify Admin API setup.

To work around this, you may need to:

  • Workaround: You can query the data without a filter and manually process the results within your app to filter out the specific items based on the inner node (like email).

Raise the Issue: Consider joining the Shopify GitHub repository and raising this concern as a feature request. This could bring attention to the issue and potentially lead to support for filtering by nested fields in future updates. Engaging with the community and Shopify developers through GitHub may help in getting support for your use case.



 

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee

View solution in original post

Replies 3 (3)

SomeUsernameHe
Shopify Partner
519 58 111

This is an accepted solution.

Currently, Shopify's GraphQL Admin API does not support filtering by inner nodes or nested fields (like contacts.customer.email) directly in queries. Filtering works well for top-level attributes like name (e.g., companies(first:10, query:"name:'My Company Name'")), but when trying to filter by nested fields (e.g., contacts.customer.email), the API ignores the query filter and returns all results.

This limitation arises because Shopify's query argument is designed to filter based only on direct attributes of the object being queried. While this works for simple filters on top-level fields, it doesn't extend to related fields within nested objects such as contacts or locations. As of now, there is no direct support for querying on inner nodes like customer emails or staff member emails in the current Shopify Admin API setup.

To work around this, you may need to:

  • Workaround: You can query the data without a filter and manually process the results within your app to filter out the specific items based on the inner node (like email).

Raise the Issue: Consider joining the Shopify GitHub repository and raising this concern as a feature request. This could bring attention to the issue and potentially lead to support for filtering by nested fields in future updates. Engaging with the community and Shopify developers through GitHub may help in getting support for your use case.



 

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee

Eric-HAN
Shopify Partner
275 30 29

Hi,there

you could try this.  This works for me

 

{
  companies(first: 10,query:"name:'Company1'") {
    edges {
      node {
        name
        contacts(first: 2,query:"email:'xxx@xxx.com'") {
          nodes {
            customer {
              email
            }
            ....
          }
        }
      }
    }
  }
}

 

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
lounik
New Member
4 0 0

@Eric-HAN 

 

it's not working, or better say: the first query works, the second query works only partially and the third one doesn't work at all. Let me explain: 

 

companies(first: 10,query:"name:'Company1'") : this query works because "name" is a direct node of company. The problem is that I know the name and the id AFTER I've loaded the company list, so I cannot  use either ID nor NAME to query the list. 

 

-  contacts(first: 2,query:"email:'xxx@xxx.com'") : this works only partially, which means that it doesn't filter the company list, so my first 10 companies are the same as before, the only difference is that with this query, I have no values for the contacts which have a different email than the one written in  the field. 

- location(first: 2,query:"email:'xxx@xxx.com'") or staffMemberAssignments(first: 2,query:"email:'xxx@xxx.com'") don't work at all, meaning that they don't even present with an empty value as the "contacts" case, they simply get ignored.