Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for custom graphQL schema #84

Open
souvikmishra opened this issue Aug 13, 2024 · 2 comments
Open

support for custom graphQL schema #84

souvikmishra opened this issue Aug 13, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@souvikmishra
Copy link
Contributor

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
Copy link
Owner

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 joshstevens19 added the enhancement New feature or request label Aug 13, 2024
@souvikmishra
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants