> For the complete documentation index, see [llms.txt](https://learn.mechanic.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.mechanic.dev/platform/graphql/basics/queries.md).

# 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

![Source: https://www.shopify.com/partners/blog/getting-started-with-graphql](https://3145272362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQrnkixbmVHvKHMwAbm%2Fuploads%2Fgit-blob-0ab7f901277fd001857be58d9c6c7151d6bb7697%2Fgetting-started-with-graphql-roots-and-nodes-diagram.gif?alt=media)

## Request three fields from a specific product

{% tabs %}
{% tab title="GraphQL Query" %}

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

{% endtab %}

{% tab title="Response" %}

```cpp
{
  "data": {
    "product": {
       "title": "t-shirt",
       "description": "This t-shirt comes in a range of colors.",
       "onlineStoreUrl": "https://test-shop.myshopify.com/products/t-shirt"
    }
  }
}
```

{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="GraphQL Query" %}

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

{% endtab %}

{% tab title="Response" %}

```cpp
{
  "data": {
    "products": {
      "edges": [
        {
          "node": {
            "id": "gid://shopify/Product/1321540321336",
            "handle": "ocean-blue-shirt",
            "variants": {
              "edges": [
                {
                  "node": {
                    "id": "gid://shopify/ProductVariant/12195005104184",
                    "displayName": "Ocean Blue Shirt - xs"
                  }
                }
              ]
            }
          }
        }
      ]
    }
  }
}
```

{% endtab %}
{% endtabs %}

## Filtering results using search queries <a href="#filtering-connections-using-a-search-query" id="filtering-connections-using-a-search-query"></a>

{% tabs %}
{% tab title="GraphQL Query" %}

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

{% endtab %}

{% tab title="Response" %}

```cpp
{
  "data": {
    "orders": {
      "edges": [
        {
          "node": {
            "id": "gid://shopify/Order/410479493176",
            "name": "#1592",
            "displayFulfillmentStatus": "FULFILLED"
          }
        },
        {
          "node": {
            "id": "gid://shopify/Order/410478542904",
            "name": "#1564",
            "displayFulfillmentStatus": "FULFILLED"
          }
        }
      ]
    }
  }
}
```

{% endtab %}
{% endtabs %}

## Great resources for learning GraphQL queries

### Key concepts to read up on

* [ ] QueryRoot
* [ ] Fields
* [ ] Connections
* [ ] First and Last
* [ ] Nodes
* [ ] Edges
* [ ] Search query

{% hint style="success" %}
<https://shopify.dev/concepts/graphql/queries>
{% endhint %}

{% hint style="success" %}
<https://www.shopify.com/partners/blog/getting-started-with-graphql>
{% endhint %}

{% hint style="success" %}
<https://graphql.org/learn/queries/>
{% endhint %}

{% hint style="success" %}
<https://www.howtographql.com/basics/2-core-concepts/>
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learn.mechanic.dev/platform/graphql/basics/queries.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
