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

Strip all Type System Directives during composition #3736

Merged
merged 13 commits into from
Jan 31, 2020

Conversation

josemarluedke
Copy link
Contributor

Fix #3565.

abernix and others added 2 commits January 29, 2020 12:37
> Note: This is not the solution, just a test that demonstrates the failure!

Recently, the beginnings of [Executable directive] support were brought into
federation through apollographql#3464
and its follow-up, apollographql#3536.

The implementation of executable directives currently in place within
federation requires that federated directives be declared identically across
all implementing services, even if their implementation is different (or a
no-op).  This is working as intended!

However, [Type system directives] need some additional pruning from the
composed schema.  Specifically, while type system directive declarations
don't need to be declared identically across implementing services, their
_definitions_ are currently (intentionally!) removed from the composed schema.

That would be fine, but the _usages_ of those directives are currently being
left in-tact, which results in validation errors within composed schemas
since the directives, while still defined in the implementing services, have
been removed.

It's certainly important that the implementing services maintain those
type system directives in order to act upon them within the services
themselves, I don't believe those directives need to be preserved in the
composed schema that runs at the gateway and is used to generate the query
plan.

This commit is mostly documenting a reproduction of an issue that was
brought to my attention and introduces what I believe is a test case to build
a solution against.

[Type system directive]: https://graphql.github.io/graphql-spec/draft/#TypeSystemDirectiveLocation
[Executable directive]: https://graphql.github.io/graphql-spec/draft/#ExecutableDirectiveLocation
@apollo-cla
Copy link

@josemarluedke: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@trevor-scheer
Copy link
Member

Thanks for taking the time to put this PR together, @josemarluedke! This is pretty close to what we want, I've created a few commits and pushed them up to show how I'd expand the scope of this a bit. Feel free to take inspiration from or cherry-pick them altogether.

In short, FIELD_DEFINITION directives aren't the only type of custom directives we want to remove from the SDL. We're interested in all custom directives.

Let me know your thoughts and when you're ready for another review. I'm also happy to land these changes myself and maintain your authorship - let me know what works best for you!

A changelog entry would also be appreciated:
https://github.com/apollographql/apollo-server/blob/master/packages/apollo-federation/CHANGELOG.md

Thanks again 😄

@josemarluedke josemarluedke changed the title Remove directives from field definition in composition Strip all Type System Directives during composition Jan 30, 2020
@josemarluedke
Copy link
Contributor Author

@trevor-scheer Thanks for creating these commits. I have cherry-picked them here. I also added an entry to the federation changelog.

Let me know if anything is missing, but I believe this is good to go.

@abernix abernix self-assigned this Jan 30, 2020
It's bad in this file altogether, but broad re-formatting of this file won't
do anything better than stomp on history.

Since this line is already changing, it's worth a fix in the same commit.
The overall height of this block seems to be a ripe opportunity to try to
lock down the re-assignment of this objects' reference, even if it wasn't
introduced by this PRs intended change.
Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Thank you so very much for taking the initiative to pick this up where I left it and run with it. LGTM. We'll get this into a release soon.

@abernix abernix added this to the Release 2.10.0 milestone Jan 31, 2020
@abernix abernix merged commit db71535 into apollographql:master Jan 31, 2020
"directives at FIELDs are executable"
directive @audit(risk: Int!) on FIELD

"directives at FIELD_DEFINITIONs are for the type-system"
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that @deprecated defies this semantic: https://www.apollographql.com/docs/graphql-tools/schema-directives/

@glasser
Copy link
Member

glasser commented Feb 13, 2020

We think this PR may accidentally be stripping @deprecated.

trevor-scheer added a commit that referenced this pull request Feb 14, 2020
This commit resolves a breaking and unintentional change from #3736.

While type-system directives _should_ be removed, @deprecated is a
special case which can and should be left in.
abernix added a commit that referenced this pull request Feb 14, 2020
This commit resolves a breaking and unintentional change from #3736.

While type-system directives _should_ be removed, @deprecated is a
special case which can and should be left in.

Co-authored-by: Jesse Rosenberger <git@jro.cc>
@abernix
Copy link
Member

abernix commented Feb 14, 2020

Correct assessment above by @glasser in #3736 (comment) and fixed by #3792

@josemarluedke josemarluedke deleted the fix-3565 branch May 27, 2020 22:39
abernix pushed a commit to apollographql/federation that referenced this pull request Sep 4, 2020
…ollo-server#3736)

* tests: Show composition failures w/ undeclared type-system directives.

> Note: This is not the solution, just a test that demonstrates the failure!

Recently, the beginnings of [Executable directive] support were brought into
federation through apollographql/apollo-server#3464
and its follow-up, apollographql/apollo-server#3536.

The implementation of executable directives currently in place within
federation requires that federated directives be declared identically across
all implementing services, even if their implementation is different (or a
no-op).  This is working as intended!

However, [Type system directives] need some additional pruning from the
composed schema.  Specifically, while type system directive declarations
don't need to be declared identically across implementing services, their
_definitions_ are currently (intentionally!) removed from the composed schema.

That would be fine, but the _usages_ of those directives are currently being
left in-tact, which results in validation errors within composed schemas
since the directives, while still defined in the implementing services, have
been removed.

It's certainly important that the implementing services maintain those
type system directives in order to act upon them within the services
themselves, I don't believe those directives need to be preserved in the
composed schema that runs at the gateway and is used to generate the query
plan.

This commit is mostly documenting a reproduction of an issue that was
brought to my attention and introduces what I believe is a test case to build
a solution against.

[Type system directive]: https://graphql.github.io/graphql-spec/draft/#TypeSystemDirectiveLocation
[Executable directive]: https://graphql.github.io/graphql-spec/draft/#ExecutableDirectiveLocation

* Remove directives from field definition in composition

* Expand functionality to all custom type system directives

* Update stripping mechanism to include all TypeSystemDirectives

* Jest auto-prettification of snapshots

* Rename var in composition to match implementation

* Add changelog entry for PR apollographql/apollo-server#3736

* nit: Line-length.

It's bad in this file altogether, but broad re-formatting of this file won't
do anything better than stomp on history.

Since this line is already changing, it's worth a fix in the same commit.

* Change `definition` to be a `const`-ant rather than `let`.

The overall height of this block seems to be a ripe opportunity to try to
lock down the re-assignment of this objects' reference, even if it wasn't
introduced by this PRs intended change.

* Add a comment about what `null` return does on visits.

* Add a comment about why we're stripping type system directives.

Co-authored-by: Jesse Rosenberger <git@jro.cc>
Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>

Apollo-Orig-Commit-AS: apollographql/apollo-server@db71535
abernix pushed a commit to apollographql/federation that referenced this pull request Sep 4, 2020
…l/apollo-server#3792)

This commit resolves a breaking and unintentional change from apollographql/apollo-server#3736.

While type-system directives _should_ be removed, @deprecated is a
special case which can and should be left in.

Co-authored-by: Jesse Rosenberger <git@jro.cc>

Apollo-Orig-Commit-AS: apollographql/apollo-server@6005f50
@XBeg9
Copy link

XBeg9 commented Sep 28, 2020

@josemarluedke any ideas why we need to strip directives from service schema (introspection) itself? it's hard for service-level-engineer to work with their own schema, moreover, how to track changes to the schema? Probably we can strip all directives from SDL, but not from schema itself. Any concerns?
Thanks

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants