# 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="https://1720293510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cPs2j0GvSzYIyVs3t35%2Fuploads%2F5YMyIlQUkdjjJbqb5CgL%2Fimage.png?alt=media&#x26;token=f6783731-2d88-43a3-8819-101518cfb696" 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="https://1720293510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cPs2j0GvSzYIyVs3t35%2Fuploads%2Fq3VyWVSNp2hNSLUjljyx%2Fimage.png?alt=media&#x26;token=473af263-1a88-4b1b-adf4-771a2a4fc3e5" 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="https://1720293510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cPs2j0GvSzYIyVs3t35%2Fuploads%2FRVOcqFNNLxFmwHh7DmXI%2Fimage.png?alt=media&#x26;token=174ef94d-b852-44c7-bcde-d7b3f310a5b9" alt=""><figcaption><p>Queries folder</p></figcaption></figure>

Add the individual queries to the folder:

<figure><img src="https://1720293510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cPs2j0GvSzYIyVs3t35%2Fuploads%2F1racmtV0o6Ng9VQGronq%2Fimage.png?alt=media&#x26;token=ea99df90-cb71-4dec-b254-837ea7848bda" 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="https://1720293510-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7cPs2j0GvSzYIyVs3t35%2Fuploads%2FvLHnBJyGIubhvvVak6Y8%2Fimage.png?alt=media&#x26;token=6b396a89-d013-4651-a2c3-4b924edaa155" 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>.
