GraphQL Indexers
Utilise SubQuery/Subsquid indexers in your app to boost efficiency and reduce loading speeds.
Last updated
Utilise SubQuery/Subsquid indexers in your app to boost efficiency and reduce loading speeds.
Last updated
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:
Subsquid:
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: .
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.
Then, in the same folder as the newly created csproj, use these commands to download the StrawberryShake tool:
Then, download the StrawberryShake.Server
Nuget package.
Lastly, initialise the GraphQL client with this command:
Example call:
I recommend creating a new folder called Queries
where you will store all of your .graphql queries.
Add the individual queries to the folder:
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.
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.
Please follow the step 5 from this documentation: .