How To Fetch A Product By ID In Shopify Checkout Validation App

New Member
4 0 1



I have followed the below tutorial and everything is working as expected


I have updated the extensions/cart-checkout-validation/input.graphql as per the below to suite my applications specific needs.


query Input {
  cart {
    buyerIdentity {
      customer {
    lines {
        merchandise {
               ...on ProductVariant {



This is working and fetching the specific data associated to the users cart that I need.


However, I addition to the above, I would also like to fetch a product and its variant (that may be unrelated to the current users cart) via ID (although in the future I will want to fetch it by tag)


How do I go about doing this?


Is this something I add to my extensions/cart-checkout-validation/input.graphql query?


I would like the product exposed in my extensions/cart-checkout-validation/src/index.js

// @ts-check
// Use JSDoc annotations for type safety
 * @typedef {import("../generated/api").InputQuery} InputQuery
 * @typedef {import("../generated/api").FunctionResult} FunctionResult
// The @shopify/shopify_function package will use the default export as your function entrypoint
export default
 * @param {InputQuery} input
 * @returns {FunctionResult}

(input) => {

    // The error
    const error = {
            "This is a test",
        target: "cart"

    const errors = [];

   // TODO: here I want to access a single product with it variant by ID
  //  Maybe something like input.my_product - if this is not the right approach,
  //  How can I go about achieving this?

    return {errors};

Please, any help, guidance or advice would be greatly appreciated.


Reply 1 (1)

Shopify Staff
1421 232 487

Hi @SoapMatt,


Thanks for your post. While we don't currently provide direct support for Functions in this forum, the public [Shopify/function-examples GitHub repository] has an active [discussion board] that might be worth checking out.
Hope you have a great day

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit or the Shopify Web Design and Development Blog