> For the complete documentation index, see [llms.txt](https://docs.a4b.vn/xflow/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.a4b.vn/xflow/developer-guide/workflow-functions/graphql.md).

# GraphQL

**Invoking a GraphQL Query**

In our workflow definition, we can then use a function definition for the `pet` query field as such:

{% code lineNumbers="true" %}

```json
{
  "functions": [
    {
      "name": "get-one-pet",
      "operation": "https://example.com/pets/graphql#query#pet",
      "type": "graphql"
    }
  ]
}
```

{% endcode %}

Note that the `operation` property has the following format for the `graphql` type:

```
<url_to_graphql_endpoint>#<literal "mutation" or "query">#<mutation_or_query_field>
```

In order to invoke this query, we would use the following `functionRef` parameters:

{% code lineNumbers="true" %}

```json
{
  "refName": "get-one-pet",
  "arguments": {
    "id": 42
  },
  "selectionSet": "{ id, name, favoriteTreat { id } }"
}
```

{% endcode %}

Which would return the following result:

{% code lineNumbers="true" %}

```json
{
  "pet": {
    "id": 42,
    "name": "Snuffles",
    "favoriteTreat": {
      "id": 9001
    }
  }
}
```

{% endcode %}

**Invoking a GraphQL Mutation**

Likewise, we would use the following function definition:

{% code lineNumbers="true" %}

```json
{
  "functions": [
    {
      "name": "create-pet",
      "operation": "https://example.com/pets/graphql#mutation#createPet",
      "type": "graphql"
    }
  ]
}
```

{% endcode %}

With the parameters for the `functionRef`:

{% code lineNumbers="true" %}

```json
{
  "refName": "create-pet",
  "arguments": {
    "pet": {
      "id": 43,
      "name":"Sadaharu",
      "favoriteTreatId": 9001
    }
  },
  "selectionSet": "{ id, name, favoriteTreat { id } }"
}
```

{% endcode %}

Which would execute the mutation, creating the object and returning the following data:

{% code lineNumbers="true" %}

```json
{
  "pet": {
    "id": 43,
    "name": "Sadaharu",
    "favoriteTreat": {
      "id": 9001
    }
  }
}
```

{% endcode %}

Note you can include expressions in both `arguments` and `selectionSet`:

{% code lineNumbers="true" %}

```json
{
  "refName": "get-one-pet",
  "arguments": {
    "id": "${ .petId }"
  },
  "selectionSet": "{ id, name, age(useDogYears: ${ .isPetADog }) { dateOfBirth, years } }"
}
```

{% endcode %}

Expressions must be evaluated before executing the operation.

Note that GraphQL Subscriptions are not supported at this time.

For more information about functions, reference the Functions definitions section.
