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

Align @external with @shareable for how it behaves on a type #2214

Merged
merged 5 commits into from
Oct 26, 2022

Conversation

clenfest
Copy link
Contributor

i.e. marking the type external makes all fields external.

Fixes #2156

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 21, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@clenfest clenfest requested a review from pcmanus October 24, 2022 14:32
Copy link
Contributor

@pcmanus pcmanus left a comment

Choose a reason for hiding this comment

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

This looks mostly good as most testing of external appears to properly rely on the ExternalTester, but unfortunately there seems to be a few exceptions within querygrapht.ts (one here and a few similar later).

I'd be suggest adding a new isExternal method similar to the hasDirective of this field, but that calls metadata.isFieldExternal instead of just checking the directive directly (this will leave the hasDirective only used once for @requires but that's probably fine).

@@ -965,6 +965,11 @@ class GraphBuilderFromSchema extends GraphBuilder {
return !!metadata && field.hasAppliedDirective(directiveFct(metadata));
}

private isExternal(field: FieldDefinition<any>): boolean {
const metadata = federationMetadata(this.schema);
return !!metadata && metadata.isFieldExternal(field);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pcmanus
I followed the pattern you had above, but is there a reason we shouldn't just assert metadata here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. We build QueryGraph using this code both for subgraph schema and for the supergraph API schema. The former will always have a metadata but the later won't, but we don't want to hard fail on it.

If we were to guard the calling of those methods with this.isFederatedSubgraph, then yes, we could assert metadata at that point, but not sure it would be much cleaner.

@@ -965,6 +965,11 @@ class GraphBuilderFromSchema extends GraphBuilder {
return !!metadata && field.hasAppliedDirective(directiveFct(metadata));
}

private isExternal(field: FieldDefinition<any>): boolean {
const metadata = federationMetadata(this.schema);
return !!metadata && metadata.isFieldExternal(field);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. We build QueryGraph using this code both for subgraph schema and for the supergraph API schema. The former will always have a metadata but the later won't, but we don't want to hard fail on it.

If we were to guard the calling of those methods with this.isFederatedSubgraph, then yes, we could assert metadata at that point, but not sure it would be much cleaner.

@clenfest clenfest merged commit 1e2dab3 into next Oct 26, 2022
@clenfest clenfest deleted the clenfest/2156-2 branch October 26, 2022 16:15
pcmanus pushed a commit to pcmanus/federation that referenced this pull request Nov 14, 2022
Historically, `@external` has always had `OBJECT` as allowed location,
but in federation 1, this was competely ignored and did nothing. Since
that has changed in federation 2 with apollographql#2214, this patch ensures any
pre-existing use of `@external` on an object type is removed by the
fed1 upgrading code.
pcmanus pushed a commit that referenced this pull request Nov 16, 2022
Historically, `@external` has always had `OBJECT` as allowed location,
but in federation 1, this was competely ignored and did nothing. Since
that has changed in federation 2 with #2214, this patch ensures any
pre-existing use of `@external` on an object type is removed by the
fed1 upgrading code.
pcmanus pushed a commit to pcmanus/federation that referenced this pull request Jan 20, 2023
For historical reasons, `@external` was legal to put on an object type
since about forever (even in federation 1) but it used to be completely
ignored. We "fixed" this support in apollographql#2214, but to limit surprised on
upgrades from fed1, the schema upgrader had been modified to drop any
`@external` on an object type (since again, those were legal but ignored
in fed1). However, the code for adding @Shareable in that same schema
upgrader was not updated correctly and so it _was_ taking `@external`
on types into account, and thus it ended up _not_ adding `@shareable`
in some cases where it should have.
pcmanus pushed a commit that referenced this pull request Jan 23, 2023
For historical reasons, `@external` was legal to put on an object type
since about forever (even in federation 1) but it used to be completely
ignored. We "fixed" this support in #2214, but to limit surprises on
upgrades from fed1, the schema upgrader had been modified to drop any
`@external` on an object type (since again, those were legal but ignored
in fed1). However, the code for adding @Shareable in that same schema
upgrader was not updated correctly and so it _was_ taking `@external`
on types into account, and thus it ended up _not_ adding `@shareable`
in some cases where it should have.
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.

2 participants