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

Discover whether PostGraphile is worth it #236

Closed
Tracked by #103
gligneul opened this issue Jan 10, 2024 · 4 comments
Closed
Tracked by #103

Discover whether PostGraphile is worth it #236

gligneul opened this issue Jan 10, 2024 · 4 comments
Assignees
Labels
! High priority #feat:graphql Feature: GraphQL API
Milestone

Comments

@gligneul
Copy link
Contributor

📚 Context

The Rollups Node must provide an interface for querying the Rollups data (inputs, outputs, and proofs). The most agreed way is to use GraphQL because it is easy to use and very flexible. We have two options when using GraphQL. The first is implementing the API by hand by fetching the data from a database. The other option is using a tool that automatically generates this API from the database.

Currently, the node implements the first option with a few thousand lines of Rust code. If we could use a tool to generate this API instead, we might avoid having to rewrite this code in Go.

One of those tools is PostGraphile. Since we already use PostgreSQL, we can evaluate how this tool behaves in the current database and how the generated API compares to our manually built one. If we like the Postgraphile API, we will create another issue to migrate to it.

@gligneul gligneul added the #feat:graphql Feature: GraphQL API label Jan 10, 2024
@gligneul gligneul added this to the 2.0.0 milestone Jan 10, 2024
@gligneul gligneul moved this to 📋 Backlog in Node Unit Jan 10, 2024
@endersonmaia
Copy link
Contributor

We used it for a while to make some aggregations in the graph-node database that weren't yet implemented in the indexing code. Let me know if you want some help evaluating this.

Sharing a little bit about the approach we took, we created a view to map what we wanted in the output to be used by Cartesi Explorer.

The first thing you'd need to check is it's possible to keep the same GraphQL schema with the one generated by postgraphile, I know it's very configurable but we didn't used those features on our case. Or you should take care about the database schema to match what postgraphile needs.

Another thing is that since there are plans to make the node work with sqlite, postgraphile won't be a fit for sqlite.

@endersonmaia
Copy link
Contributor

Since we're on this, in case we want to offer a REST API directly from the database:

@gligneul
Copy link
Contributor Author

Thanks for the feedback, @endersonmaia!

Sharing a little bit about the approach we took, we created a view to map what we wanted in the output to be used by Cartesi Explorer.

I was thinking about creating a completely separate database for the GraphQL API. Then, we could make the schema for this separate database stable and have the freedom to change anything we want in the internal node database.

Your approach might be a good option as well.

The first thing you'd need to check is it's possible to keep the same GraphQL schema with the one generated by postgraphile, I know it's very configurable but we didn't used those features on our case. Or you should take care about the database schema to match what postgraphile needs.

We don't need it to be 100% compatible. We can align this change with a major version and break compatibility slightly. In particular, the pagination/filter queries will probably be better in Postgraphile, so we could use this moment to improve the API.

Another thing is that since there are plans to make the node work with sqlite, postgraphile won't be a fit for sqlite.

This is not part of the roadmap anymore. I want to focus on a single environment, which is the one that has Postgres.

Since we're on this, in case we want to offer a REST API directly from the database:

If define a good database schema, this can be plugged from the outside.

@gligneul gligneul added the ! High priority label Jan 16, 2024
@gligneul gligneul moved this from 📋 Backlog to 🏗 In progress in Node Unit Jan 29, 2024
@GMKrieger GMKrieger moved this from 🏗 In progress to ✅ Done in Node Unit Feb 7, 2024
@endersonmaia
Copy link
Contributor

Just found this other option that's Rust and it's a Postgres extension, so no other service needs to be deployed since it will be inside the database itself.

It has its own scaling challenges since it will run within the database, but I thought it was good to bookmark it.

https://github.com/supabase/pg_graphql

@marcelstanley marcelstanley changed the title Discover whether PostGraphile is worth Discover whether PostGraphile is worth it Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
! High priority #feat:graphql Feature: GraphQL API
Projects
Status: Done
Development

No branches or pull requests

4 participants