# GraphQL

## Description

[Open in GitHub](https://github.com/serverless-cqrs/graphql-example)

{% hint style="info" %}
First, make sure you've run `npm i -g serverless` and added your [AWS credentials](https://serverless.com/framework/docs/providers/aws/guide/credentials/).
{% endhint %}

{% hint style="warning" %}
Deploying for the first time can take 10-20 minutes since it needs to create the ElasticSearch instance. If there is an error, you may get `ROLLBACK_IN_PROGRESS` the next time you try to deploy. Give it a few minutes and then try again.
{% endhint %}

```
git clone git@github.com:serverless-cqrs/graphql-example.git
cd graphql-example
npm i
serverless deploy
```

Once deployed, navigate to the returned endpoint url and you'll see the **graphql playground**, where you can run the following queries:

```graphql
mutation {
  addTodo(id: "123", title: "Get Milk")
}
```

```graphql
query {
  getById(id: "123") {
    id
    todos {
      title
      completed
    }
  }
}
```

{% hint style="danger" %}
The AWS Free Tier covers most of these services, but running an ElasticSearch instance on AWS can be expensive. Make sure to run `serverless remove` once you're done.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.serverless-cqrs.com/examples/graphql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
