Comments (6)
Variable batching
would probably be the best approach and it was actually proposed as an addition to the GraphQL spec a while back (#517). That being said even if it is accepted as part of the official spec it would take a while for a wide adoption... as such I think the only viable option* is the alias batching
.
*many frameworks do support request batching
but since it is not part of an official spec, I'd imagine there are still quite a few servers might not support it.
from composite-schemas-spec.
Variable batching gets my vote; definitely feels the most GraphQL-y; and for people who use DataLoaders on context
already they just need to share the context across the multiple queries and executing them in parallel should have minimal overhead.
from composite-schemas-spec.
My take on batching non-unique operation bodies.
When multiple operations are batched together, there is a risk. Fetching 'Bar' consumes 2s, while 'Foo' is optimized and only takes 90ms.
In such cases, the overall time required for the batched operations will be determined by the slowest one.
While this is true for all types of batching, enforcing a single operation body helps minimize the impact, as the execution flow is likely to be consistent for all variables.
We could stream the response of each execution, but I don't think it will improve performance of a gateway, as every batched operation is most likely required to resolve first, before resolving the next step of a query planner.
from composite-schemas-spec.
As you mentioned, only the Alias Batching
option is compatible with existing GraphQL servers.
Opting for any alternative method forces the gateway to be aware about which GraphQL servers support this method and it may become challenging.
Either the schema says "I'm compatible with X" (I'd prefer this option) or the GraphQL server (requires some form of "introspection" and becomes a mess when you deal with multiple instances or gradual deployments).
IMO Variable Batching
is strongest option here.
We need to make sure it's compliant with GraphQL spec (not graphql-over-http spec).
from composite-schemas-spec.
Variable batching also seems like the best option if we know that we can always execute the same operation and we are only ever selecting one entity but changing the id.
Wouldn't we want to though also support selecting different entities from one subgraph fetch? If we have to resolve 3 Foos
but 10 Bars
using variable batching would require use to have a nullable entity fetcher, which I suppose could be a requirement, or would it better to scope it per-request?
[
{
"query": "query getFoo($a: Int!) { foo(a: $a) }",
"variables": {
"a": 1
}
},
{
"query": "query getFoo($a: Int!) { foo(a: $a) }",
"variables": {
"a": 2
}
},
{
"query": "query getBar($b: Int!) { bar(b: $b) }",
"variables": {
"b": 1
}
},
]
VS
{
"query": "query getFooAndBar($a: Int, b: Int) { foo(a: $a) bar(b: $b) }",
"variables": [
{ "a": 1 }, { "a": 2 }, { "b": 1 },
]
},
We could also add the option of request AND variable batching
[
{
"query": "query getFoo($a: Int!) { foo(a: $a) }",
"variables": [
{"a": 1 }, {"a": 2 }
]
},
{
"query": "query getBar($b: Int!) { bar(b: $b) }",
"variables": {
"b": 1
}
},
]
from composite-schemas-spec.
I understand that this has much wider implications, but just to put it out there: the source Source Schema 1 could also provide a root field which can be queried likes this:
query($ids: [ID!]! ,$requirements: [ProductDimensionInput!]) {
ordersDimensions(ids: $ids, dimensions: $requirements)
}
This would not require any special batching mechanism at all.
from composite-schemas-spec.
Related Issues (11)
- Should entity resolvers be limited to the root level. HOT 1
- Better terms for supergraph, subgraph and public API needed. HOT 12
- Can we come up with a better term for `@entityResolver` / `@finder`? HOT 4
- Do we agree execution mechanisms are out of scope for this specification? HOT 3
- What term should we use for a federated gateway / router in this specification? HOT 14
- More GraphQL native expression for FieldSelection? HOT 9
- Terminology: gateway v.s. distributed executor HOT 2
- Composite Schemas vs. Distributed/Federated HOT 2
- Finding the right Batching protocol HOT 1
- Discuss the effect on public schema of `@internal` directive HOT 4
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 composite-schemas-spec.