tailcall
tailcall copied to clipboard
Feature Request: Support for Apollo Federation in Tailcall
Summary
Enable Tailcall to support Apollo Federation by adding a flag in the @server
directive. When enabled, this flag will support the _entities
query, allowing Tailcall to function as a subgraph in a federated architecture.
Detailed Description
To integrate Apollo Federation with Tailcall, we propose the following enhancements:
-
Flag Addition in
@server
:- Introduce a new flag within the
@server
directive to enable federation support. - When this flag is activated, Tailcall will automatically handle the
_entities
query, essential for Apollo Federation's distributed schema architecture.
- Introduce a new flag within the
-
Support for Resolver Directives on Types:
- Enable resolver directives like
@http
,@grpc
,@const
, and others to be applied directly on Types. - This will allow Tailcall to infer the key fields required for federation based on the resolver configuration.
- Enable resolver directives like
-
Key Inference:
- Analyze the resolvers attached to Types and automatically infer the appropriate
@key
directive. - Example:
- For
@http(path: "/users/{{.value.id}}")
, the inferred key would be@key(fields: "id")
. - For the query:
The inferred key would be@http(path: "/users/", query: [ {key: "id", value: "{{.value.id}}"}, {key: "name", value: "{{.value.name}}"}, {key: "org_id", value: "{{.value.organisation.id}}"}, {key: "org_name", value: "{{.value.organisation.name}}"} ])
@key(fields: "id name organisation {id, name}")
.
- For
- If multiple resolvers are attached to the same type, multiple keys will be inferred and handled accordingly.
- Analyze the resolvers attached to Types and automatically infer the appropriate
-
Support for
_entities
Query:- Implement the
_entities
query required by Apollo Federation. - Example of how the query to the subgraph would look:
type Query { _entities(representations: [_Any!]!): [_Entity]! }
- Example query:
query ($representations: [_Any!]!) { _entities(representations: $representations) { ... on User { id username } } }
- Corresponding variable:
{ "representations": [ { "__typename": "User", "id": "5" } ] }
- Corresponding variable:
- Example query:
- Implement the
References
-
For a reference implementation of Apollo Federation, see the async-graphQL implementation.
-
Subgraph Documentation
Technical Requirements
- Integration & Unit Tests are required.
- Update the documentation on website