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

GraphQL Query Planner #732

Closed
rmosolgo opened this issue May 22, 2017 · 4 comments
Closed

GraphQL Query Planner #732

rmosolgo opened this issue May 22, 2017 · 4 comments

Comments

@rmosolgo
Copy link
Owner

rmosolgo commented May 22, 2017

I'm really interested in leveraging GraphQL's "compile-bility" a bit more. For example, it should be possible to inspect a GraphQL query and write the correct SQL queries (and/or external service calls) to fulfill that query.

The API of my dreams involves two parts:

  1. Some way for users to specify how fields are fulfilled, and how those specifications may be combined
  2. A first-class graphql-ruby API for surfacing its execution plan based on those specifications. (eg puts MySchema.plan(query_string, context: ctx))

I think the resulting system could be very powerful: you could make some predictions about database access before running the query and iterate on your configuration to make it correct and efficient.

However, it will also be very hard 😄

Also, it's important for me to make this incrementally adoptable. I think this will be manageable: the default plan for every field is "just call field.resolve", I think that's the starting point.

GraphQL::InternalRepresentation is a de facto query plan right now, but it has some issues:

  • It depends on query variable values: Namely, @skip/@include are applied at that time. Nodes are removed from the tree if they are skipped, and query variable values are required to do that. To make the plan more portable, we should allow static planning (from a query string alone)
  • No user-friendly APIs: it's build to make execution easy, not to make inspection easy. As a result, it's hard to answer simple questions like "is field X selected?".
  • Implementation issues: its approach to fragment inlining is not good (this is because it converts the query into a deterministic finite automaton, I think a more efficient approach would be to use a NFA with runtime switches as part of the machine, this is how it used to work)

My goal will be to make it compatible with Schema-from-IDL as discussed in #727 and useable somehow via DSL.

What do you think, would this API be useful in your system? Are there other considerations we should make?

@rmosolgo rmosolgo added this to the 1.7.0 milestone May 22, 2017
@bessey
Copy link
Contributor

bessey commented Jun 4, 2017

I think this is really intriguing, and have been thinking about it myself. With the current API its pretty trivial to avoid N+1s, but not so easy to avoid over-fetching within a single table. If there were some way to annotate a field with the column(s) it will access, and have the parent node's resolve take this into account, the penalty for accessing a couple of fields on a wide table could be totally eliminated.

@fameoflight
Copy link

@rmosolgo just wondering what happened to this? did you ever try to implement this?

@xpol
Copy link

xpol commented Jul 28, 2018

There is Join Monster did this, but it is for JS.

@rmosolgo
Copy link
Owner Author

I looked at this some, but I think instead I will make a multi-pass interpreter instead, keep an eye on #1394

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

No branches or pull requests

4 participants