Skip to content

Instantly share code, notes, and snippets.

@jorgemasta
Last active November 16, 2023 07:07
Show Gist options
  • Select an option

  • Save jorgemasta/fc5b29c59bd66d26ce3d28c1b71130b3 to your computer and use it in GitHub Desktop.

Select an option

Save jorgemasta/fc5b29c59bd66d26ce3d28c1b71130b3 to your computer and use it in GitHub Desktop.

Revisions

  1. jorgemasta revised this gist Feb 5, 2021. No changes.
  2. jorgemasta created this gist Feb 5, 2021.
    113 changes: 113 additions & 0 deletions custom-query.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,113 @@
    import { productPrices, multipleChoiceOptionFragment } from '@framework/api/fragments/product';

    const productInfoFragment = /* GraphQL */ `
    fragment productInfo on Product {
    entityId
    name
    path
    brand {
    entityId
    }
    description
    prices {
    ...productPrices
    }
    images {
    edges {
    node {
    urlOriginal
    altText
    isDefault
    }
    }
    }
    variants {
    edges {
    node {
    entityId
    defaultImage {
    urlOriginal
    altText
    isDefault
    }
    }
    }
    }
    productOptions {
    edges {
    node {
    __typename
    entityId
    displayName
    ...multipleChoiceOption
    }
    }
    }
    relatedProducts {
    edges {
    node {
    name
    }
    }
    }
    localeMeta: metafields(namespace: $locale, keys: ["name", "description"])
    @include(if: $hasLocale) {
    edges {
    node {
    key
    value
    }
    }
    }
    }
    ${productPrices}
    ${multipleChoiceOptionFragment}
    `

    const productConnectionFragment = /* GraphQL */ `
    fragment productConnnection on ProductConnection {
    pageInfo {
    startCursor
    endCursor
    }
    edges {
    cursor
    node {
    ...productInfo
    }
    }
    }
    ${productInfoFragment}
    `

    export const customGetAllProductsQuery = /* GraphQL */ `
    query getAllProducts(
    $hasLocale: Boolean = false
    $locale: String = "null"
    $entityIds: [Int!]
    $first: Int = 10
    $products: Boolean = false
    $featuredProducts: Boolean = false
    $bestSellingProducts: Boolean = false
    $newestProducts: Boolean = false
    ) {
    site {
    products(first: $first, entityIds: $entityIds) @include(if: $products) {
    ...productConnnection
    }
    featuredProducts(first: $first) @include(if: $featuredProducts) {
    ...productConnnection
    }
    bestSellingProducts(first: $first) @include(if: $bestSellingProducts) {
    ...productConnnection
    }
    newestProducts(first: $first) @include(if: $newestProducts) {
    ...productConnnection
    }
    }
    }
    ${productConnectionFragment}
    `