apollographql / apollographql/federation

[federation] Service composition modifies Subscription type

Open
#288 5 comments 6 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
725
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

# Description
The `composeAndValidate(...)` function provided by the federation package transforms the Subscription type provided by any of the input services into a type extension, but does not properly handle the modified node afterword. Any schema containing a Subscription type passed to this function will cause it to throw an error.

The transformation happens to all root operation types (Query, Mutation, Subscription) in the schema normalization stage. The Subscription type is specified [here](https://github.com/apollographql/apollo-server/blob/2f5f29204132c726795c32e5a8487e5fdbded95d/packages/apollo-federation/src/composition/normalize.ts#L27), and the actual node update happens in the same file [here](https://github.com/apollographql/apollo-server/blob/2f5f29204132c726795c32e5a8487e5fdbded95d/packages/apollo-federation/src/composition/normalize.ts#L150).

Later, in the composition stage, there are checks to ensure the Query and Mutation base types exist as empty nodes so that they can be extended, but no check is made for the Subscription type. These checks can be seen [here](https://github.com/apollographql/apollo-server/blob/master/packages/apollo-federation/src/composition/compose.ts#L314).

# Proposal
Ideally, a check would be added to ensure that the base Subscription type exists and create the correct node if it does not. Alternatively, the Subscription type could be removed from the normalization stage.

I would be happy to submit a PR addressing this issue if the Apollo team agrees that the functionality should be modified.

Contributor guide

Open the contributing guide

Research direction

Read packages/apollo-federation/src/composition/normalize.ts at the Subscription root-operation handling and packages/apollo-federation/src/composition/compose.ts around the Query and Mutation base-type checks. Trace how a schema containing Subscription moves through normalization and composition; done means composeAndValidate no longer throws for that schema and the Subscription base type is handled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.