Multiple simultaneous 'Query' type queries, is it possible?

Solved
Tourist
7 2 0

OK, so the following code works, but each named query, 'Vendor' and 'Title', has to be run separately, and it seems to me that there really, really, really should be a way to run them together? 

I'm using the GraphiQL app in the browser that is accessible from the 'apps' menu. 

 

query Vendor($vendor: String!){  
products(first:20, query: $vendor) {
     edges {
      node {
        totalInventory
        title
        handle
        vendor
        description
        featuredImage {
          originalSrc
          altText
        }
        images(first: 3) {
          edges {
            node {
              originalSrc
              altText
            }
          }
        }
        options {
          values
        }
       variants(first:10) {
          edges {
            node {
              price
            }
          }
        }
      }
    }
  }
}


query Title($title: String!) {
  products(first:20, query: $title) {  
    edges {
      node {
        totalInventory
        title
        handle
        vendor
        description
        featuredImage {
          originalSrc
          altText
        }
        images(first: 3) {
          edges {
            node {
              originalSrc
              altText
            }
          }
        }
        options {
          values
        }
       variants(first:10) {
          edges {
            node {
              price
            }
          }
        }
      }
    }
  }
} 

Query Variables

{
  "vendor": "Liam Fashions",
  "title": ""
}

When I click on the 'run' arrow I get a drop-down where I have to choose either the 'Vendor' or 'Title' query. It will not just run both. 

 

I realize there might be a way to do this programmatically, but maybe not, is this a GraphQL limitation? I was hoping I could solve it with aliases, but that did not work. 

 

Also, I cannot, no matter what I try, I cannot filter on variant price, or any other variant property. If there was any other way to flatten this schema, I would just give up on trying to use the variant property altogether. It's just too aggravating. But I don't see any other more easily accessible properties that do the same thing??? 

 

Why did Shopify make the schema so jiggy jaggy??? And then take away Explorer?????? That stupid 'Docs' sidebar is almost like not having any help at all! It's like, "Hey that's a String! That's Money!" OK, thanks! How do I use it? No? Not gonna connect those dots whatsoever, eh? Well OK then... :(

 

Sorry. Just frustrated again... 😫

 

....

0 Likes

Success.

Shopify Staff
Shopify Staff
1546 77 231

Are you just trying to search on two properties at once? You can do that with an AND  clause in the search string:

 

query {
  orders(first:50, query:"test:true AND email:foo@bar123.com") {
    edges {
      node {
        id
        test
        email
      }
    }
  }
}

The search strings you give to query arguments use Shopify search syntax, this might be helpful to you: https://help.shopify.com/en/api/getting-started/search-syntax

 

Cheers.

1 Like
Tourist
7 2 0

OK, thank you Alex, yes, that syntax does work! I learned something new today! 😃

 

However, I still won't be able to combine two variables into one query, will I? Variables will be necessary (I think!) if I want to expose objects' properties on a form for selection. I might just have to write separate queries, maybe???

 

I DO, however, still have a big problem; I really really want to know how to access the nested attributes of the 'variants' element. See how there is a 'title' property for both the 'products' object and the 'variants' object? This is something that really seems necessary to basic app development, in my early stage of learning how to do this. 

 

query{  
products(first:20, query: "title:'Classic Leather Jacket'") {
  
    edges {
      node {       
 --->   title
        vendor
        description
       variants(first:10, query: "title:'xs'") {   
          edges {
            node {
              price
 ---->        title
            }
          }
        }
      }
    }
  }
}

In the above example, the first query in the 'products' object, for "title: 'Classic Leather Jacket'" works as expected; however, when I add the second query, the "title:'xs'" (the 'xs' title attribute is definitely there, in the data, for that item) I get an error message saying "Field 'variants' doesn't accept argument 'query'". 

 

Why? Why can't I use the same type of query on variants that I use on products? 

 

Is there any way to query the properties of variants? I mean, the actual useful properties, not just first. last, etc.

Not just these (products looks the same except it also has 'query' in addition to all of these) (Yes I know I just answered one of my own questions.):

TYPE
ProductVariantConnection!

first: Int Returns up to the first n elements from the list. after: String Returns the elements that come after the specified cursor. last: Int Returns up to the last n elements from the list. before: String Returns the elements that come before the specified cursor. reverse: Boolean = false Reverse the order of the underlying list. sortKey: ProductVariantSortKeys = POSITION Sort the underlying list by the given key.

But still, HOW? How do you query THESE specific attributes?

 

variants-attributes.pngvariants-attributes

 

 

0 Likes
Shopify Staff
Shopify Staff
1546 77 231

Re: nested queries:

 

Good question, I'm not sure why you can't query variants within ProductEdges. I'll ask around about that.

 

Regarding querying against properties that don't already fall under the "queryable" fields - there is not presently a way to do this in a supported manner, but that feedback is valuable.

 

I'll keep you posted on how the nested queries questioning goes on my end.

 

Cheers.

1 Like

Success.

Tourist
7 2 0

You know what... I think I am beginning to understand why there are several popular plugins such as 'shopify-buy' and others in the node.js ecosystem. 

 

I have nothing against using these plugins, but I wanted to understand as much as possible how to use the Shopify API and query the data, and not just be using plugins without understanding at least on a fundamental level, how to get the underlying data. 

 

It might just be beyond where I'm at right now, and I might just be better off to use the available plugins. 

0 Likes