Queries

GraphQL is a powerful query language that allows you to request data from a GraphQL server like Shopify's APIs. Queries are capable from requesting specific fields of single resources, nested resources, and lists of resources.

A GraphQL API models data as nodes connected by edges. A node is an object that has a global ID, such as an Order object or Product object. You can fetch data about an individual node, or you can follow the edges to fetch data about a collection of related nodes. At each node, you specify the fields that you want to retrieve. - https://shopify.dev/concepts/graphql/queries

Visualizing edges and nodes

Request three fields from a specific product

query {
  product(id: "gid://shopify/Product/1925886804024") {
    title
    description
    onlineStoreUrl
  }
}

Request the first three products in our store, including their first three variants

query {
  products(first:3) {
    edges {
      node {
        id
        handle
        variants(first:3) {
          edges {
            node {
              id
              displayName
            }
          }
        }
      }
    }
  }
}

Filtering results using search queries

query {
  orders(first:2, query:"fulfillment_status:shipped") {
    edges {
      node {
        id
        name
        displayFulfillmentStatus
      }
    }
  }
}

Great resources for learning GraphQL queries

Key concepts to read up on

Last updated