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 handling of core/link when definitions are provided or partially so #1662

Merged
merged 3 commits into from
Apr 1, 2022

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented Mar 30, 2022

This fixes the issue described on #1657 but also fix some related handling of errors (that were not properly surfaced previously). I made a separate PR because the issue was not so much with composition than with subgraph validations, so I preferred moving tests in the existing test file dedicated to those subgraph validations. But also, the repro from #1657 uses some definitions that are not exactly the ones that have been used so far and so it doesn't pass for those reasons.

@netlify
Copy link

netlify bot commented Mar 30, 2022

👷 Deploy request for apollo-federation-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ee7ac74

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 30, 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.

Copy link
Contributor

@queerviolet queerviolet left a comment

Choose a reason for hiding this comment

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

(just a quick drive-by comment, will play with this and offer more shortly. thanks for the quick turn-around!)

@@ -1499,6 +1509,10 @@ export class SchemaDefinition extends SchemaElement<SchemaDefinition, Schema> {
const imports = extractCoreFeatureImports(url, schemaDirective);
const core = new CoreFeature(url, args.as ?? url.name, schemaDirective, imports, args.for);
Schema.prototype['markAsCoreSchema'].call(schema, core);
// We also any core features that may have been added before we saw the @link for link itself
Copy link
Contributor

Choose a reason for hiding this comment

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

i am not 100% sure i understand what case this is handling, so maybe disregard, but the @core and @link specs both require that the bootstrap @link is the first one in the document; any prior @links should be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's the an artifact of how the code works right now. Essentially, because the abstraction is mutable, the way incomplete schema are expanded is done by taking the input and adding what's missing. So when we get an input that only has a @link to the federation spec, but no @link-to-link-itself, we end up adding that @link-to-link-itself to a document hat already has another existing @link and this code ensure that pre-existing feature is still tracker correctly.

To be clear, the resulting "final" document still end up with the @link-to-link as the first one on the SchemaDefinition, the code is just need due to way incomplete schema are auto-completed.

the @core and @link specs both require that the bootstrap @link is the first one in the document

As a minor aside, this made me notice that the current core/v0.2 spec (https://specs.apollo.dev/core/v0.2/) only ever talk about SchemaDefinition in the bootstrap/feature collection descriptions. Since we've making extensive doc of putting @link on SchemaExtension in our docs/examples, we should make sure to clarify their handling.

Copy link
Contributor

@queerviolet queerviolet 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 good! can we call the spec we're using here https://specs.apollo.dev/link/v0.3? it's a fairly significant change, and i'd like to take a little space for us to update and review the spec before declaring it v1.0

@pcmanus
Copy link
Contributor Author

pcmanus commented Mar 31, 2022

can we call the spec we're using here https://specs.apollo.dev/link/v0.3?

I'm afraid it's not that simple because we've had a few preview released with link/v1.0, and the last of those release even use that in supergraphs, so backpedaling to link/v0.3 now would mean the next release cannot read the supergraphs of the previous release. Of course, we're in "preview", so breaking change are not completely out of question, but I know we've been a lot more careful with it for preview.

Fwiw, my personal opinion is that since @link is used as an integral part of user schema in fed2, then it essentially becomes GA as fed2 gets GA, and I think calling it 1.0 make sense, especially in terms of backward-compatibility guarantees associated with being out of the 0.x phase.

Copy link
Contributor

@queerviolet queerviolet left a comment

Choose a reason for hiding this comment

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

yeah, i figured that was probably the case. it's a bummer we pinned 1.0 semantics without spec review.

there's one specific change i'd like us to make if possible, but we can always do it in another pr.


private createDefinitionArgumentSpecifications(schema: Schema, nameInSchema?: string): { args: ArgumentSpecification[], errors: GraphQLError[] } {
const args: ArgumentSpecification[] = [
{ name: this.urlArgName(), type: new NonNullType(schema.stringType()) },
Copy link
Contributor

Choose a reason for hiding this comment

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

can we weaken this to just String for the moment? i'd like v1.0 to maintain universality. there are a few mechanisms to do this, but @link(url: null, import: "looks__namespacedButIsnt") is one way to handle it, and i'd like us not to have painted ourselves into a corner by shipping it like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense. And was simple-enough, so made the change in the PR (with a test to double-check it's a safe change, that is that we were still correctly reading previously generated definition having the non-nullable type).

@pcmanus pcmanus force-pushed the fix-expanding-core branch from de7470c to ee7ac74 Compare April 1, 2022 08:39
@pcmanus pcmanus merged commit d2a5ae7 into apollographql:main Apr 1, 2022
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