I already have an app with all the products listed that currently just redirects to the web on checkout. I want to be able to allow the user to see the variants of the products before opening the web and possible even use ApplePay, but I can't seem to figure out a way to pull that data from the SDK. I have the products ID and I have this code below for when I figure out how to get the global IDs.
let id = GraphQL.ID(rawValue: "")
let query = Storefront.buildQuery { $0
.node(id: id) { $0
.onProduct { $0
.id()
.title()
}
}
}
Any help/guidance would be greatly appreciated.
How are you getting the IDs in the first place? You can get a list of IDs with a products graphql query on the storefront, which you would be able to use for the part you're sharing.
I don't strongly recommend this, but if you already have a list of REST API IDs (ex. 1234567), you can construct a GID: gid://shopify/Product/9895276099
The base64 encoded version of that is the final representation of a GID. Again though, I don't recommend doing this (assuming the GID structure) if you can avoid it. It's best not to depend on that being the pattern forever. If we, for example, changed the structure of GIDs, your app might break. It's best to get the IDs with GraphQL itself first if possible.
Cheers.
Currently, you're not able to fetch a portion of the GID. Your best option is to parse out the section of the string that you need from the GraphQL GID.
Shayne | Developer @ 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 Shopify.dev or the Shopify Web Design and Development Blog
User | Count |
---|---|
13 | |
13 | |
6 | |
6 | |
5 |