# GraphQL Indexers

Blockchains by design are not really design to be efficient for reading the data that is saved on it. Instead, the main focus of blockchains was to optimise for writing. That means that reading the actual data from archive nodes is an after-thought.

Indexers specialize in indexing the on-chain data to allow faster and more efficient reading.

One of the other benefits that indexing brings is the ability to efficiently filter and order the data.

We will not explain here how to setup your own indexer, however, you can follow these guides to make your own:

* SubQuery: <https://academy.subquery.network/>
* Subsquid: <https://docs.sqd.ai/>

## Setup the Indexer csproj

The approach will be similar to generating and registering your own new blockchain. Let's once again hand over the tedious work to a code generator, that will automatically update with each recompilation.

To do that, we use StrawberryShake V13 according to this guide: <https://chillicream.com/docs/strawberryshake/v13/get-started/console>.

Firstly, you will want to create a new csproj (It can be anything, but I use new Class Library) and I remove the `class1.cs` file. Also, for consistancy, place this csproj in the `Generated` folder, since the resulting c# code will be generated and never rewritten by the hands of developers.

<figure><img src="/files/CgnN0SLYutvH9N6NPOqo" alt=""><figcaption><p>Create Class Library csproj</p></figcaption></figure>

Then, in the same folder as the newly created csproj, use these commands to download the StrawberryShake tool:

```sh
dotnet new tool-manifest
```

```sh
dotnet tool install StrawberryShake.Tools --local
```

Then, download the `StrawberryShake.Server` Nuget package.

<figure><img src="/files/06pWemNUuvGxfbvMP3xG" alt=""><figcaption><p>StrawberryShake.Server Nuget package</p></figcaption></figure>

Lastly, initialise the GraphQL client with this command:

```sh
dotnet graphql init <your-http-graphql-endpoint> -n <name-of-the-client> -p .
```

Example call:

```
dotnet graphql init https://workshop.chillicream.com/graphql/ -n MyGraphQLClient -p .
```

## Add Queries

I recommend creating a new folder called `Queries` where you will store all of your .graphql queries.

<figure><img src="/files/NF3Hit8UJCzUZYoZNPgN" alt=""><figcaption><p>Queries folder</p></figcaption></figure>

Add the individual queries to the folder:

<figure><img src="/files/EMlxM8cZooQnL9h5l2aK" alt=""><figcaption><p>.graphql Query</p></figcaption></figure>

Visual Studio will update the .csproj file to include the new .graphql file, however it does this incorrectly. You will have to remove the "Queries/" from the path to the file, otherwise the StrawberryShake code generator will not recognize the graphql file and will skip it.

<figure><img src="/files/aXIgQapO9MxV8UmnlCs1" alt=""><figcaption><p>Correctly set query path in .csproj</p></figcaption></figure>

Now, after rebuilding this project, you will be able to use it in your own app.

Also, do not forget to add the reference to this project.

## Use the GraphQL Client in your application

Please follow the *step 5* from this documentation: <https://chillicream.com/docs/strawberryshake/v13/get-started/console>.


---

# 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://plutolabs.gitbook.io/plutoframework/make-your-application/graphql-indexers.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.
