-
Notifications
You must be signed in to change notification settings - Fork 12
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
Proposal: Simplified Key Definition in GraphQL Composite Schemas #168
Comments
@fotoetienne The main reason we landed on the current That wouldn't really be addressed by this proposal: it would simplify complex keys, but not allow for multiple keys and differences between subgraphs in what keys they support. Also, I don't believe it would eliminate the need for variable batching, because we still need that to support There's yet another reason we originally went with A first thought might be to ask users to define batched lookup fields. Instead of If you think about what a subquery would look like, it becomes clear this won't allow us to pass in entity-specific additional data. In the example below, each product's query ($upcs: [String!]!, $size: Float, $weight: Float) {
products(upcs: $upcs) {
name
description
shippingCost(size: $size, weight: $weight)
}
} Defining |
Should we separate the concept of multiple keys from that of composite keys? We could support multiple keys, while still requiring that a key is a single scalar field. |
That's true. But @require isn't required (pun intended) for many use cases. @require could be an optional composite v1.1 feature that comes later once variable batching is widely available. |
Yeah, we should at least clearly explain the difference.
I think the underlying issue here is supporting current usage and retaining compatibility with Apollo Federation. Users do rely on composite keys and We could decide to mark those features as optional in the spec, to allow for simplified implementations, but my worry is that this would fragment the ecosystem. |
Copying from graphql/composite-schemas-wg#440
Introduction
This proposal suggests starting with a simpler definition of keys in GraphQL composite schemas by restricting keys to a single value. This approach aims to simplify the composite schema specification, the gateway-subgraph contract, and gateway implementations.
Proposal
Simplified Key Definition
Instead of complex key definitions, we propose using a single scalar value for keys:
or
Handling Complex Keys
For cases where the underlying model requires a more complex key, subgraph tooling can provide a helper method to create the composite-schemas key. An object-level key directive could be used as a convenience, interpreted only by the subgraph server:
The subgraph's GraphQL framework can automatically add the composite key:
This feature would be optional and could help subgraphs using the current spec to be grandfathered in.
Pros
Cons
The text was updated successfully, but these errors were encountered: