joshstevens19 / rindexer

A no-code blazing fast EVM indexer tool built in rust.
https://rindexer.xyz
MIT License
267 stars 24 forks source link

support for custom graphQL schema #84

Open souvikmishra opened 1 month ago

souvikmishra commented 1 month ago

Hey, first of all really love the project. I have used the no-code version a few times now and it has been a breeze. Recently, I tried using the rust version since I wanted to have some flexibility with indexing as well as the graphQL schema. So the issue goes like this, I used to use "The Graph", in that we can create a schema.graphql which lets us add our custom entities that show up in their explorer and can be queried. For example, I have this entity in my schema.graphql

type Provider @entity {
  id: ID! #id same as owner address
  cp: String
  live: Boolean
} 

and I have this custom event handler:

// ProviderAdded is the event that the contract fires, so think of this as the custom indexer
export function handleProviderAdded(event: ProviderAdded): void { 
    const id = event.params.provider.toHex();
    const provider = new Provider(id);  // <--- calling the entity constructor 

    provider.cp = event.params.cp; // <--- modify the cp string
    provider.live = true;  // <--- modify the live boolean
    provider.save();   // <--- now we just save and this event is indexed in the Provider entity
}

Now, since I am new to the rust version I might be asking a silly question, but is there a way to achieve this kind of behavior with rindexer right now? Any help/discussion would be really helpful. Feel free to ask any other particulars that are needed to clarify things.

joshstevens19 commented 1 month ago

hey so at the moment we have not fleshed out the schema generation; the best way to do this at the moment is creating your own create.sql which creates the tables you want and this, in turn would be your graphql interface. You would turn creating tables off https://rindexer.xyz/docs/start-building/yaml-config/storage#disable_create_tables and you then can generate the types and indexer and write the data where you need it to go in the handlers. It is on the backlog to make this a lot easier but at the moment, its a bit more complex

souvikmishra commented 1 month ago

Thank you for such a quick reply. I'll try this new approach now. Also, can't wait for this feature to be available natively. God bless.