Comments (4)
Awesome @benjie, thanks for the detailed response! Excited to dive in an explore this more
PS funny enough, my exploration of grafast was actually on a plane back from a conference
from crystal.
Hi @brandonwestcott; creating a @dataplan/graphql
for this exact purpose is on my long term plan! Would be great for you to start this early.
You should use step classes to track which attributes are accessed. You'll end up with a lot of steps during planning, this is expected - as one of the final steps they can be optimized away. You might want to look at the broad idea (not the specifics, they're way way way too complicated for this use case!) of how the Postgres integration works; broadly:
- PgSelectStep represents a
select ... from ...
operation - PgSelectSingleStep represents a single row from the result
- PgClassExpressionStep represents an expression on a single row, for example access to a particular column, or a Postgres function call or similar
Critically all these exist before optimization, but when optimization happens many of them are inlined into their parents/etc and it all collapses down to a much simpler plan.
You might want to look at how the loadOne()
step works too, since that tracks access to .get(field)
so it knows which fields to request. .get(key)
is becoming a convention, and will probably be more explicitly a protected pattern in a future version (e.g. "everything that has a "get" method must obey X, Y and Z").
There are some subtleties to GraphQL in this regard; for example in Postgres every PgSelectStep can be an SQL statement on its own, or can be inlined into a parent SQL statement, but that's not true in GraphQL - only root level fields can be queried on the root, all others maintain their heirarchy.
Further, when polymorphism comes into it you may need to query additional attributes that won't actually be returned in the result. This probably isn't an issue, but does mean that you might need to do careful management of aliases in outgoing queries to prevent users shaping incoming queries maliciously causing you issues (e.g. fragment Foo on User { __typename: username }
might trick your system if you're not careful!).
I think you would want:
- A step class representing a GraphQL operation
- A step class representing a GraphQL field
- A step class representing a GraphQL inline fragment
- A step class representing a GraphQL named fragment
Deduplication of each of these should follow effectively the field collection rules in the GraphQL spec (if a field is specified twice with two different sets of arguments (and the same response key) then that would be forbidden by the GraphQL spec's validation, but what we'd do would be to just assign two different aliases to it when we request it from the remote server).
Try and think very locally in steps, e.g. each layer is just representing a single selection on the parent selection set, or similar. Then your big complex system can be composed of all these small isolated features that are easy (ish) to reason about.
I hope this helps! I'd love to track your progress on this.
from crystal.
Ooo, I thought this rung a bell! Turns out that I started work on this back September last year, on the plane over to GraphQLConf! You can actually see my timezone change in the commit timestamps :D
The code in this branch is super out of date, a lot of the patterns have changed now, but perhaps it'll give some inspiration? Also looks like I stopped halfway through some refactoring or something, so I've just added that just now... no idea if it's coherent.
https://github.com/graphile/crystal/tree/dataplan-graphql
from crystal.
Keeping this open to track @dataplan/graphql
. Let me know if you need any input on it (you may get faster responses on Discord; make sure you give yourself the Dev role).
from crystal.
Related Issues (20)
- Graphile Export: detect hasOwn keys set on functions that aren't exportable
- Connection string with localhost don't work in library mode HOT 6
- "Gather" plugin example: treating unique indexes similarly to unique constraints HOT 1
- Document the new "early exit" and "global dependencies" features
- Epic: removing $step.eval()
- Masked errors when output to console should include path, etc.
- `makeWrapPlansAfterArgumentsHaveBeenAppliedPlugin` - solve confusion
- PostGraphileRelayPreset bug: mutation with "null" foreign key value does not work (returns null) HOT 1
- How does Postgraphile integrate with Apache AGE? HOT 1
- Polymorphism - union containing members of an interface plus another; how to plan?
- Create tests for middleware system (grafast, grafserv)
- multi tenancy and update pg schema without restart HOT 1
- Koa middleware does not call next() for all scenarios HOT 7
- (v5) I'd like get a generic executor from `build.input.pgRegistry` inside a `makeExtendSchemaPlugin`. HOT 1
- Questions based on initial experience with v5 polymorphism HOT 6
- The v5 documentation for crud mutations mentions both `insert` and `create` as values for the `@behavior` smart tag. HOT 2
- PgExecutor cache is not cleared between subscription payloads
- Subscription error causes socket to disconnect
- `PostGraphileRelayPreset` does not eliminate `Row` in `ByRowId`
- Polymorphic types offer mutations under some circumstances? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal.