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

Fix federation orphan types #584

Merged

Conversation

paulpdaniels
Copy link
Collaborator

In federation it is possible that you declare a type which has no entry point in the graph but which is nonetheless required to be part of the outgoing schema. Consider:

// Schema A
@key(fields:"id")
type User {
  id: String!
}

type Query {
  me: User!
}
// Schema B
@key(fields:"id")
extends type User {
  id: String! @external
  team: Team!
}

type Query {
  team(id: String): Team
}

In the above graphs they should become federated with User gaining the team field through declaration, however currently the implementation ignores types which don't have entry points into the graph from Query so the users extension would be skipped.

This PR allows the schema to include these orphan types as long as there is an entity resolver defined for the typel.

@@ -96,11 +96,13 @@ trait Federation {
_fieldSet: FieldSet = FieldSet("")
)

val withSDL = original.withAdditionalTypes(resolvers.map(_.toType))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add these only here to avoid polluting the original graph since these new types don't have any utility since they couldn't be accessed through a normal query anyway.

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ghostdogpr ghostdogpr merged commit 494f4ab into ghostdogpr:master Sep 8, 2020
@paulpdaniels paulpdaniels deleted the fix-federation-orphan-types branch September 8, 2020 10:26
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

Successfully merging this pull request may close these issues.

None yet

2 participants