rindexer icon indicating copy to clipboard operation
rindexer copied to clipboard

support for custom graphQL schema

Open souvikmishra opened this issue 1 year ago • 2 comments

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.

souvikmishra avatar Aug 13 '24 10:08 souvikmishra

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

joshstevens19 avatar Aug 13 '24 16:08 joshstevens19

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.

souvikmishra avatar Aug 14 '24 05:08 souvikmishra