A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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... 😫
....
Solved! Go to the solution
This is an accepted solution.
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.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
This is an accepted solution.
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.
This is an accepted solution.
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.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
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?
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.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
This is an accepted solution.
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.
Have you figured out why the query argument can't be used simultaneously with products and variants? Is there a way around it?
query getProductType {
products(first: 20, query: "product_type:microphone status:ACTIVE inventory_total:>0") {
edges {
node {
id
title
hasOnlyDefaultVariant
descriptionHtml
images(first: 25) {
edges {
node {
originalSrc
altText
}
}
}
tags
totalInventory
vendor
variants(first: 5, sortKey: TITLE, query: "inventory_quantity:>0") {
edges {
node {
image {
id
}
price
id
title
inventoryQuantity
}
}
}
}
}
}
}
{
"errors": [
{
"message": "Field 'variants' doesn't accept argument 'query'",
"locations": [
{
"line": 20,
"column": 44
}
],
"path": [
"query getProductType",
"products",
"edges",
"node",
"variants",
"query"
],
"extensions": {
"code": "argumentNotAccepted",
"name": "variants",
"typeName": "Field",
"argumentName": "query"
}
}
]
}