Skip to content
Developer home
X3

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  {
  xtremX3Products  {
    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 {
  xtremX3Products {
    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'}") {
  xtremX3Products {
    product {
      query(filter: $productFilter, first: 5, orderBy: "{ code: 1  }") {
        edges {
          node {
            code
            productCategory {
              code
            }
            accountingCode
            description1
            localizedDescription1
          }
          cursor
        }
        pageInfo {
          endCursor
          hasNextPage
        }
      }
    }
  }
}

Query on Product-site

{
  xtremX3Products {
    productSite {
      query {
        edges {
          node {
            _id
            packaging
            isLocationManaged
            isLicensePlateNumberManaged
            stockManagementMode
            isPackingManaged
            distinctCountOfSublots
            distinctCountOfLots
            distinctCountOfLocations
            distinctCountOfStockQuantity
            countOfStockRecords
            distinctCountOfLotAndSublot
          }
        }
      }
    }
  }
}