GraphQL Indexers

Utilise SubQuery/Subsquid indexers in your app to boost efficiency and reduce loading speeds.

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:

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.

Create Class Library csproj

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

dotnet new tool-manifest
dotnet tool install StrawberryShake.Tools --local

Then, download the StrawberryShake.Server Nuget package.

StrawberryShake.Server Nuget package

Lastly, initialise the GraphQL client with this command:

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.

Queries folder

Add the individual queries to the folder:

.graphql Query

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.

Correctly set query path in .csproj

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.

Last updated