-
Notifications
You must be signed in to change notification settings - Fork 8
composition result differences for compose directives #298
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
base: directives-fix
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -521,6 +521,96 @@ | |
| `); | ||
| }); | ||
|
|
||
| test("compose directive definition conflict (does the order matter? 1)", () => { | ||
| const result = api.composeServices([ | ||
| { | ||
| name: "a", | ||
| url: "http://a.com", | ||
| typeDefs: graphql` | ||
| extend schema | ||
| @link(url: "https://specs.apollo.dev/federation/${version}", import: ["@composeDirective"]) | ||
| @link(url: "https://a.dev/a/v1.0", import: ["@a"]) | ||
| @composeDirective(name: "@a") | ||
|
|
||
| directive @a(name: String!) on QUERY | MUTATION | ||
|
|
||
| type Query { | ||
| a: Int | ||
| } | ||
| `, | ||
| }, | ||
| { | ||
| name: "b", | ||
| url: "http://b.com", | ||
| typeDefs: graphql` | ||
| extend schema | ||
| @link(url: "https://specs.apollo.dev/federation/${version}", import: ["@composeDirective"]) | ||
| @link(url: "https://a.dev/a/v1.0", import: ["@a"]) | ||
| @composeDirective(name: "@a") | ||
|
|
||
|
|
||
| directive @a(name: ID!) on QUERY | MUTATION | ||
|
|
||
|
|
||
| type Query { | ||
| b: Int | ||
| } | ||
| `, | ||
| }, | ||
| ]); | ||
|
|
||
| expect(result.errors).toEqual(undefined); | ||
| assertCompositionSuccess(result); | ||
| expect(result.supergraphSdl).toContainGraphQL(graphql` | ||
|
Check failure on line 564 in __tests__/supergraph/base.spec.ts
|
||
| directive @a(name: String!) on QUERY | MUTATION | ||
| `); | ||
| }); | ||
|
|
||
| test("compose directive definition conflict (does the order matter? 2)", () => { | ||
| const result = api.composeServices([ | ||
| { | ||
| name: "b", | ||
| url: "http://b.com", | ||
| typeDefs: graphql` | ||
| extend schema | ||
| @link(url: "https://specs.apollo.dev/federation/${version}", import: ["@composeDirective"]) | ||
| @link(url: "https://a.dev/a/v1.0", import: ["@a"]) | ||
| @composeDirective(name: "@a") | ||
|
|
||
|
|
||
| directive @a(name: ID!) on QUERY | MUTATION | ||
|
|
||
|
|
||
| type Query { | ||
| b: Int | ||
| } | ||
| `, | ||
| }, | ||
| { | ||
| name: "a", | ||
| url: "http://a.com", | ||
| typeDefs: graphql` | ||
| extend schema | ||
| @link(url: "https://specs.apollo.dev/federation/${version}", import: ["@composeDirective"]) | ||
| @link(url: "https://a.dev/a/v1.0", import: ["@a"]) | ||
| @composeDirective(name: "@a") | ||
|
|
||
| directive @a(name: String!) on QUERY | MUTATION | ||
|
|
||
| type Query { | ||
| a: Int | ||
| } | ||
| `, | ||
| }, | ||
| ]); | ||
|
|
||
| expect(result.errors).toEqual(undefined); | ||
| assertCompositionSuccess(result); | ||
| expect(result.supergraphSdl).toContainGraphQL(graphql` | ||
|
Check failure on line 609 in __tests__/supergraph/base.spec.ts
|
||
| directive @a(name: String!) on QUERY | MUTATION | ||
| `); | ||
| }); | ||
|
|
||
| test("composed directive with VARIABLE_DEFINITION and FIELD locations is preserved in supergraph", () => { | ||
| const result = api.composeServices([ | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions validate that a conflict in directive argument types (
String!vsID!) results in a successful composition where one type is silently chosen based on subgraph sorting. However, the PR description suggests that this behavior is inconsistent with expectations ('The Guild composition raises an exception') and notes that Apollo's similar 'silent winner' approach is problematic (😓).By using
assertCompositionSuccess, these tests codify what appears to be a bug or a missing validation rule. If the intention is to ensure that such conflicts are caught (similar to theFIELD_ARGUMENT_TYPE_MISMATCHmentioned in the description), these tests should instead expect a validation error. Codifying the current inconsistent behavior as a success may make it harder to fix later.