Skip to content
Developerhome

Example GraphQL queries for Products

  Less than to read

Two lists of five products by product category, sorted by code in descending order, with aliases

query MyNamedQueryWithAliases  {
  xtremX3MasterData  {
    product  {
      subcoProduct: query (filter: "{productCategory: 'SUBCO'}", first: 5, orderBy: "{ code: -1  }") {
        edges {
          node {
            code
            accountingCode
            description1
            localizedDescription1
            productCategory{
              code
            }
          }
        }
      }
      sfiniProduct: query(filter: "{productCategory: 'SFINI'}", first: 5, orderBy: "{ code: -1  }") {
        edges {
          node {
            code
            accountingCode
            description1
            localizedDescription1
            productCategory{
              code
            }
          }
        }
      }
    }
  }
}

Two lists of five products by product category (using fragment syntax)

query MyNamedQueryWithAliasesAndFragment {
  xtremX3MasterData {
    product {
      leftComparison: query(filter: "{productCategory: 'SUBCO'}") {
        ...comparisonFields
      }
      rightComparison: query(filter: "{productCategory: 'SFINI'}") {
        ...comparisonFields
      }
    }
  }
}

fragment comparisonFields on Product_Query {
  edges {
    node {
      code
      productCategory {
        code
      }
      accountingCode
      description1
      localizedDescription1
    }
  }
}

First five products sorted by code in ascending order, with pagination and filtered using variable with default value

# If you need to use another value than the default value of
# $productFilter, just put it in the Query Variables zone, e.g :
# {"productFilter" : "{productCategory: 'SUBCO'}"}

query ProductsInCategory($productFilter: String = "{productCategory: 'SFINI'}") {
  xtremX3MasterData {
    product {
      query(filter: $productFilter, first: 5, orderBy: "{ code: 1  }") {
        edges {
          node {
            code
            productCategory {
              code
            }
            accountingCode
            description1
            localizedDescription1
          }
          cursor
        }
        pageInfo {
          endCursor
          hasNextPage
        }
      }
    }
  }
}