single query to get everything about the first product

single query to get everything about the first product

PremierEPOS
Shopify Partner
5 0 0

Hi everyone

 

Bit of a long shot, I have spent weeks on this query

 

I want to run a single query, this gets the first product.

 

Now I dont want just the product, i want everything connected to that product and i mean everything.

 

Currently I can get the first product and with it

 

product details

  image details

  media details (video's etc)

  variants

    product options inside variants

      option values inside the product options

 

I need to be able to get the InventoryItem and InventoryLevel - these are the missing bits.

 

Everytime i think i am getting close, i constantly get quantity no longer exists, quantities requires names,

 

I just want a single query to return everything about the first product

 

I have the pagenext working, that took some brain power - it shouldnt off.

 

Any help would be appricated, thanks

 

PremierEPOS_0-1723073572976.png

 

I have attached a screen shot of what i am working on, I can get the quanities returned in a round about way but i need to know the inventoryitemid, the inventotylevelid (gid's)

 

Many thanks

 

Dave.

Reply 1 (1)

Kyle_liu
Shopify Partner
157 23 27

Hi @PremierEPOS 

 

Can the following code meet your needs?

 

query getProduct ($id: ID!){
  product(id: $id) {
    title
    tags
    handle
    availablePublicationsCount{
        count
        precision
    }
    category {
        id
        name
        level
        isLeaf
    }
    description
    onlineStoreUrl
    compareAtPriceRange{
        maxVariantCompareAtPrice{
            currencyCode
            amount
        }
        minVariantCompareAtPrice{
            currencyCode
            amount
        }
    }
    defaultCursor
    featuredImage{
        altText
        url
    }
    hasOnlyDefaultVariant
    hasOutOfStockVariants
    hasVariantsThatRequiresComponents
    requiresSellingPlan
    isGiftCard
    legacyResourceId
    images(first: 10){
        edges{
            node{
                id
                src
                altText
                
            }
        }
    }
    updatedAt
    variantsCount{
        count
        precision
    }
    variants(first: 10){
        edges{
            node{
                id
                title
                displayName
                price
                compareAtPrice
                image {
                    id
                    url
                }
                inventoryItem {
                    countryCodeOfOrigin
                    id 
                    createdAt
                    duplicateSkuCount
                    harmonizedSystemCode
                    inventoryHistoryUrl
                    inventoryLevel(locationId: "gid://shopify/Location/69855576286"){
                        id
                        canDeactivate
                        createdAt
                        deactivationAlert
                        location{
                            isActive
                        }
                    }
                    locationsCount{
                        count
                        precision
                    }
                    measurement{
                        id
                        weight{
                            unit
                            value
                        }
                    }
                    provinceCodeOfOrigin
                    requiresShipping
                    sku
                    tracked
                    unitCost{
                        amount
                        currencyCode
                    }
                    updatedAt
                }
                inventoryPolicy
                inventoryQuantity
            }
        }
    }
    variantsCount{
        count
        precision
    }
    options(first: 10){
        id
        linkedMetafield{
            key
            namespace
        }
        name
        values
        optionValues {
            id
            linkedMetafieldValue
            name
            hasVariants
            swatch{
                color
                image{
                    fileStatus
                }
            }
            
        }
        position
    }
    totalInventory
    seo{
        title
        description
    }
    status
    tags
    vendor
  }
}

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me on (liushuaicc@shinetechsoftware.com)