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): Skip missing types while iterating over field directive usages #868

Merged
merged 5 commits into from
Jul 13, 2021

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented Jul 9, 2021

With the addition of @tag and @inaccessible directives, we inadvertently began adding invalid types to our typeNameToFieldDirectivesMap. These "invalid" types exist in the map (but not the schema) when a type is extended but never actually defined anywhere.

We can simply check the existence of each type in the schema before performing any work there and skip any iterations where a type is not found.

Fixes #866

trevor-scheer added a commit that referenced this pull request Jul 9, 2021
@abernix abernix added this to the MM-2021-07 milestone Jul 13, 2021
name: 'inventory',
typeDefs: gql`
extend type Product @key(fields: "id") {
id: ID! @external @tag(name: "hi from inventory")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this error out because of #869?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well it explicitly should not error out, which it was doing before. #869 updates this test with the new composition error that's returned (it's based against this branch for simplicity). So I'll leave this as is since it's properly addressed in the next PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

// Now that we have a constructed schema, we can filter this map based on types
// that made it into the schema successfully. Types that didn't make it into the
// schema will have related composition errors.
const filteredTypeNameToFieldDirectivesMap = filterMap(
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of filtering here, wouldn't it be easier to make addFederationMetadataToSchemaNodes skip types in typeNameToFieldDirectivesMap that don't exist in the schema? That avoids the need for filterMap and recreating a Map even if nothing gets removed. It seems to me the code here could use a check.

Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

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

Assuming the feedback is addressed/responded to accordingly, this should move forward to unblock work. Please file follow up
Issues for anything we should circle back to before preview/GA. Thanks!

@trevor-scheer trevor-scheer merged commit cf67713 into main Jul 13, 2021
@trevor-scheer trevor-scheer deleted the trevor/fix-866 branch July 13, 2021 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

composeAndValidate() unexpectedly throws when using @tag/@inaccessible
3 participants