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

Proposal: Simplified Key Definition in GraphQL Composite Schemas #168

Open
smyrick opened this issue Feb 7, 2025 · 0 comments
Open

Proposal: Simplified Key Definition in GraphQL Composite Schemas #168

smyrick opened this issue Feb 7, 2025 · 0 comments

Comments

@smyrick
Copy link
Contributor

smyrick commented Feb 7, 2025

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:

type Foo {
    id: ID! @key
    v: String
}

or

type Foo implements Node {
    id: ID!
    v: String
}

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:

type Foo @key(fields: "fooId") {
    fooId: String!
    v: String
}

The subgraph's GraphQL framework can automatically add the composite key:

type Foo {
    id: ID! # auto-generated
    fooId: String!
    v: String
}

This feature would be optional and could help subgraphs using the current spec to be grandfathered in.

Pros

  • Simpler Composite Schema Spec: Easier to understand and implement.
  • Simpler Gateway-Subgraph Contract: Reduces complexity in interactions. Easier troubleshooting.
  • Simpler Gateway Implementations: Less complex, potentially fewer bugs.
  • Batch Lookup: Simplifies batch lookup, eliminates need for GraphQL spec changes
  • Simple cases are easy. Complex cases are possible: Only subgraphs that desired complex keys need to take on any additional complexity

Cons

  • Server-Side Tooling: In order to have the same level of key flexibility and convenience, additional tooling is required.
  • Compatibility with Fed2: Subgraphs using complex keys with current Fed2 spec would need adaptation (though this could be done automatically through tooling).
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

1 participant