admin graphql query filter not working for inner nodes

Solved

admin graphql query filter not working for inner nodes

lounik
Visitor
2 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:'[email protected]'") {
...
}

 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
515 57 109

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 2 (2)

SomeUsernameHe
Shopify Partner
515 57 109

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
186 25 20

Hi,there

you could try this.  This works for me

 

{
  companies(first: 10,query:"name:'Company1'") {
    edges {
      node {
        name
        contacts(first: 2,query:"email:'[email protected]'") {
          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