The Graph: schemas for subgraphs
Building good, accurate schema is a crucial part of The Graph’s subgraph deployment process. Don’t quite know what it is? Here’s a top-level, kinda basic overview, jumping off point…
So, what is schema?
In short… schema defines a collection of things or types and the relationship between those types. Every data graph uses schema to define the types of data it includes.
It’s built using GraphQL and the specifications of its architecture includes an easily read schema definition language (or SDL) that you use to define your schema and store it as a string.
Like this:
In that very, very, basic schema example there, every Book has an Author and every author has a list of books. By defining these type relationships in a unified schema, you can see exactly what data is available. Requests for specific subsets of that data can be made with optimised queries.
What to consider when creating schema
Anyone looking to create schema should really have a good understanding and feel for the subject matter and project they’re creating. Kinda goes without saying, but it’s still important to keep in mind.
The subject matter can, of course, be anything, for example: sports teams and season statistics; or music artists, labels, albums and chart positions; or countries’ importing and exporting information, to name just a few. The possibilities for subject matter are almost literally endless.
Plain and simple, having a good understanding of your subject matter will help you determine what data will be useful for a subgraph user.
In conclusion
Schema is at the heart of any subgraph implementation. Schema describes the functionality available to the users/applications that connect to it. Users and applications can query the schema within its capabilities to find the data needed. It’s crucial framework for The Graph — a decentralized protocol for indexing and querying data from the Ethereum blockchain (with other blockchains to follow).
Dig deeper
Delve into The Graph. Read on here:
https://thegraph.com/docs/define-a-subgraph#the-graphql-schema
https://thegraph.com/docs/deploy-a-subgraph#create-the-subgraph