Skip to content

Commit 26549ff

Browse files
authored
[Fusion] Fixed issue causing duplicated forwarded variables (#8311)
1 parent 8377e54 commit 26549ff

File tree

32 files changed

+278
-20
lines changed

32 files changed

+278
-20
lines changed

src/HotChocolate/Fusion/src/Core/Planning/RequestFormatters/RequestDocumentFormatter.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,16 +608,11 @@ protected void TryForwardVariable(
608608
var originalVarDef = context.Operation.Definition.VariableDefinitions
609609
.First(t => t.Variable.Equals(variableValue, SyntaxComparison.Syntax));
610610

611-
if (resolver is null || !resolver.ArgumentTypes.TryGetValue(argumentName, out var type))
612-
{
613-
type = originalVarDef.Type;
614-
}
615-
616611
context.ForwardedVariables.Add(
617612
new VariableDefinitionNode(
618613
null,
619614
variableValue,
620-
type,
615+
originalVarDef.Type,
621616
originalVarDef.DefaultValue,
622617
Array.Empty<DirectiveNode>()));
623618
}

src/HotChocolate/Fusion/test/CommandLine.Tests/__snapshots__/ComposeCommandTests.Compose_Fusion_Graph.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ schema {
1010

1111
type Query {
1212
errorField: String
13+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
1314
userById(id: ID!): User
1415
users: [User!]!
1516
usersById(ids: [ID!]!): [User!]!
@@ -66,6 +67,7 @@ schema @fusion(version: 1) @transport(subgraph: "Accounts", group: "Fusion", loc
6667

6768
type Query {
6869
errorField: String @resolver(subgraph: "Accounts", select: "{ errorField }")
70+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int @variable(subgraph: "Accounts", name: "first", argument: "first") @variable(subgraph: "Accounts", name: "second", argument: "second") @resolver(subgraph: "Accounts", select: "{ testWithTwoArgumentsDifferingNullability(first: $first, second: $second) }", arguments: [ { name: "first", type: "Int!" }, { name: "second", type: "Int" } ])
6971
userById(id: ID!): User @variable(subgraph: "Accounts", name: "id", argument: "id") @resolver(subgraph: "Accounts", select: "{ userById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ])
7072
users: [User!]! @resolver(subgraph: "Accounts", select: "{ users }")
7173
usersById(ids: [ID!]!): [User!]! @variable(subgraph: "Accounts", name: "ids", argument: "ids") @resolver(subgraph: "Accounts", select: "{ usersById(ids: $ids) }", arguments: [ { name: "ids", type: "[ID!]!" } ])
@@ -117,7 +119,7 @@ scalar Date
117119
```json
118120
{
119121
"Name": "Accounts",
120-
"Schema": "schema {\n query: Query\n mutation: Mutation\n}\n\n\"The node interface is implemented by entities that have a global unique identifier.\"\ninterface Node {\n id: ID!\n}\n\ntype Query {\n \"Fetches an object given its ID.\"\n node(\"ID of the object.\" id: ID!): Node\n \"Lookup nodes by a list of IDs.\"\n nodes(\"The list of node IDs.\" ids: [ID!]!): [Node]!\n users: [User!]!\n userById(id: ID!): User\n usersById(ids: [ID!]!): [User!]!\n errorField: String\n viewer: Viewer!\n}\n\ntype Mutation {\n addUser(input: AddUserInput!): AddUserPayload!\n}\n\n\"The `Date` scalar represents an ISO-8601 compliant date type.\"\nscalar Date\n\ntype Viewer {\n user: User\n data: SomeData!\n}\n\ntype User implements Node {\n errorField: String\n id: ID!\n name: String!\n birthdate: Date!\n username: String!\n}\n\ntype SomeData {\n accountValue: String!\n}\n\ninput AddUserInput {\n name: String!\n username: String!\n birthdate: Date!\n}\n\ntype AddUserPayload {\n user: User\n}",
122+
"Schema": "schema {\n query: Query\n mutation: Mutation\n}\n\n\"The node interface is implemented by entities that have a global unique identifier.\"\ninterface Node {\n id: ID!\n}\n\ntype Query {\n \"Fetches an object given its ID.\"\n node(\"ID of the object.\" id: ID!): Node\n \"Lookup nodes by a list of IDs.\"\n nodes(\"The list of node IDs.\" ids: [ID!]!): [Node]!\n users: [User!]!\n userById(id: ID!): User\n usersById(ids: [ID!]!): [User!]!\n errorField: String\n testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int\n viewer: Viewer!\n}\n\ntype Mutation {\n addUser(input: AddUserInput!): AddUserPayload!\n}\n\n\"The `Date` scalar represents an ISO-8601 compliant date type.\"\nscalar Date\n\ntype User implements Node {\n errorField: String\n id: ID!\n name: String!\n birthdate: Date!\n username: String!\n}\n\ntype Viewer {\n user: User\n data: SomeData!\n}\n\ntype SomeData {\n accountValue: String!\n}\n\ninput AddUserInput {\n name: String!\n username: String!\n birthdate: Date!\n}\n\ntype AddUserPayload {\n user: User\n}",
121123
"Extensions": [
122124
"extend type Query {\n userById(id: ID!\n @is(field: \"id\")): User!\n usersById(ids: [ID!]!\n @is(field: \"id\")): [User!]!\n}"
123125
],

src/HotChocolate/Fusion/test/CommandLine.Tests/__snapshots__/ComposeCommandTests.Compose_Fusion_Graph_Append_Subgraph.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Query {
1515
reviewById(id: ID!): Review
1616
reviewOrAuthor: ReviewOrAuthor!
1717
reviews: [Review!]!
18+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
1819
userById(id: ID!): User
1920
users: [User!]!
2021
usersById(ids: [ID!]!): [User!]!
@@ -111,6 +112,7 @@ type Query {
111112
reviewById(id: ID!): Review @variable(subgraph: "Reviews2", name: "id", argument: "id") @resolver(subgraph: "Reviews2", select: "{ reviewById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ])
112113
reviewOrAuthor: ReviewOrAuthor! @resolver(subgraph: "Reviews2", select: "{ reviewOrAuthor }")
113114
reviews: [Review!]! @resolver(subgraph: "Reviews2", select: "{ reviews }")
115+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int @variable(subgraph: "Accounts", name: "first", argument: "first") @variable(subgraph: "Accounts", name: "second", argument: "second") @resolver(subgraph: "Accounts", select: "{ testWithTwoArgumentsDifferingNullability(first: $first, second: $second) }", arguments: [ { name: "first", type: "Int!" }, { name: "second", type: "Int" } ])
114116
userById(id: ID!): User @variable(subgraph: "Accounts", name: "id", argument: "id") @resolver(subgraph: "Accounts", select: "{ userById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ]) @variable(subgraph: "Reviews2", name: "id", argument: "id") @resolver(subgraph: "Reviews2", select: "{ authorById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ])
115117
users: [User!]! @resolver(subgraph: "Accounts", select: "{ users }")
116118
usersById(ids: [ID!]!): [User!]! @variable(subgraph: "Accounts", name: "ids", argument: "ids") @resolver(subgraph: "Accounts", select: "{ usersById(ids: $ids) }", arguments: [ { name: "ids", type: "[ID!]!" } ])
@@ -197,7 +199,7 @@ scalar Date
197199
```json
198200
{
199201
"Name": "Accounts",
200-
"Schema": "schema {\n query: Query\n mutation: Mutation\n}\n\n\"The node interface is implemented by entities that have a global unique identifier.\"\ninterface Node {\n id: ID!\n}\n\ntype Query {\n \"Fetches an object given its ID.\"\n node(\"ID of the object.\" id: ID!): Node\n \"Lookup nodes by a list of IDs.\"\n nodes(\"The list of node IDs.\" ids: [ID!]!): [Node]!\n users: [User!]!\n userById(id: ID!): User\n usersById(ids: [ID!]!): [User!]!\n errorField: String\n viewer: Viewer!\n}\n\ntype Mutation {\n addUser(input: AddUserInput!): AddUserPayload!\n}\n\n\"The `Date` scalar represents an ISO-8601 compliant date type.\"\nscalar Date\n\ntype Viewer {\n user: User\n data: SomeData!\n}\n\ntype User implements Node {\n errorField: String\n id: ID!\n name: String!\n birthdate: Date!\n username: String!\n}\n\ntype SomeData {\n accountValue: String!\n}\n\ninput AddUserInput {\n name: String!\n username: String!\n birthdate: Date!\n}\n\ntype AddUserPayload {\n user: User\n}",
202+
"Schema": "schema {\n query: Query\n mutation: Mutation\n}\n\n\"The node interface is implemented by entities that have a global unique identifier.\"\ninterface Node {\n id: ID!\n}\n\ntype Query {\n \"Fetches an object given its ID.\"\n node(\"ID of the object.\" id: ID!): Node\n \"Lookup nodes by a list of IDs.\"\n nodes(\"The list of node IDs.\" ids: [ID!]!): [Node]!\n users: [User!]!\n userById(id: ID!): User\n usersById(ids: [ID!]!): [User!]!\n errorField: String\n testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int\n viewer: Viewer!\n}\n\ntype Mutation {\n addUser(input: AddUserInput!): AddUserPayload!\n}\n\n\"The `Date` scalar represents an ISO-8601 compliant date type.\"\nscalar Date\n\ntype User implements Node {\n errorField: String\n id: ID!\n name: String!\n birthdate: Date!\n username: String!\n}\n\ntype Viewer {\n user: User\n data: SomeData!\n}\n\ntype SomeData {\n accountValue: String!\n}\n\ninput AddUserInput {\n name: String!\n username: String!\n birthdate: Date!\n}\n\ntype AddUserPayload {\n user: User\n}",
201203
"Extensions": [
202204
"extend type Query {\n userById(id: ID!\n @is(field: \"id\")): User!\n usersById(ids: [ID!]!\n @is(field: \"id\")): [User!]!\n}"
203205
],

src/HotChocolate/Fusion/test/CommandLine.Tests/__snapshots__/ComposeCommandTests.Compose_Fusion_Graph_Remove_Subgraph.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ schema {
1010

1111
type Query {
1212
errorField: String
13+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
1314
userById(id: ID!): User
1415
users: [User!]!
1516
usersById(ids: [ID!]!): [User!]!
@@ -66,6 +67,7 @@ schema @fusion(version: 1) @transport(subgraph: "Accounts", group: "Fusion", loc
6667

6768
type Query {
6869
errorField: String @resolver(subgraph: "Accounts", select: "{ errorField }")
70+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int @variable(subgraph: "Accounts", name: "first", argument: "first") @variable(subgraph: "Accounts", name: "second", argument: "second") @resolver(subgraph: "Accounts", select: "{ testWithTwoArgumentsDifferingNullability(first: $first, second: $second) }", arguments: [ { name: "first", type: "Int!" }, { name: "second", type: "Int" } ])
6971
userById(id: ID!): User @variable(subgraph: "Accounts", name: "id", argument: "id") @resolver(subgraph: "Accounts", select: "{ userById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ])
7072
users: [User!]! @resolver(subgraph: "Accounts", select: "{ users }")
7173
usersById(ids: [ID!]!): [User!]! @variable(subgraph: "Accounts", name: "ids", argument: "ids") @resolver(subgraph: "Accounts", select: "{ usersById(ids: $ids) }", arguments: [ { name: "ids", type: "[ID!]!" } ])
@@ -117,7 +119,7 @@ scalar Date
117119
```json
118120
{
119121
"Name": "Accounts",
120-
"Schema": "schema {\n query: Query\n mutation: Mutation\n}\n\n\"The node interface is implemented by entities that have a global unique identifier.\"\ninterface Node {\n id: ID!\n}\n\ntype Query {\n \"Fetches an object given its ID.\"\n node(\"ID of the object.\" id: ID!): Node\n \"Lookup nodes by a list of IDs.\"\n nodes(\"The list of node IDs.\" ids: [ID!]!): [Node]!\n users: [User!]!\n userById(id: ID!): User\n usersById(ids: [ID!]!): [User!]!\n errorField: String\n viewer: Viewer!\n}\n\ntype Mutation {\n addUser(input: AddUserInput!): AddUserPayload!\n}\n\n\"The `Date` scalar represents an ISO-8601 compliant date type.\"\nscalar Date\n\ntype Viewer {\n user: User\n data: SomeData!\n}\n\ntype User implements Node {\n errorField: String\n id: ID!\n name: String!\n birthdate: Date!\n username: String!\n}\n\ntype SomeData {\n accountValue: String!\n}\n\ninput AddUserInput {\n name: String!\n username: String!\n birthdate: Date!\n}\n\ntype AddUserPayload {\n user: User\n}",
122+
"Schema": "schema {\n query: Query\n mutation: Mutation\n}\n\n\"The node interface is implemented by entities that have a global unique identifier.\"\ninterface Node {\n id: ID!\n}\n\ntype Query {\n \"Fetches an object given its ID.\"\n node(\"ID of the object.\" id: ID!): Node\n \"Lookup nodes by a list of IDs.\"\n nodes(\"The list of node IDs.\" ids: [ID!]!): [Node]!\n users: [User!]!\n userById(id: ID!): User\n usersById(ids: [ID!]!): [User!]!\n errorField: String\n testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int\n viewer: Viewer!\n}\n\ntype Mutation {\n addUser(input: AddUserInput!): AddUserPayload!\n}\n\n\"The `Date` scalar represents an ISO-8601 compliant date type.\"\nscalar Date\n\ntype User implements Node {\n errorField: String\n id: ID!\n name: String!\n birthdate: Date!\n username: String!\n}\n\ntype Viewer {\n user: User\n data: SomeData!\n}\n\ntype SomeData {\n accountValue: String!\n}\n\ninput AddUserInput {\n name: String!\n username: String!\n birthdate: Date!\n}\n\ntype AddUserPayload {\n user: User\n}",
121123
"Extensions": [
122124
"extend type Query {\n userById(id: ID!\n @is(field: \"id\")): User!\n usersById(ids: [ID!]!\n @is(field: \"id\")): [User!]!\n}"
123125
],

src/HotChocolate/Fusion/test/CommandLine.Tests/__snapshots__/PackageHelperTests.Create_Extract_Extensions.snap

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Query {
2424
userById(id: ID!): User
2525
usersById(ids: [ID!]!): [User!]!
2626
errorField: String
27+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
2728
viewer: Viewer!
2829
}
2930

@@ -34,11 +35,6 @@ type Mutation {
3435
"The `Date` scalar represents an ISO-8601 compliant date type."
3536
scalar Date
3637

37-
type Viewer {
38-
user: User
39-
data: SomeData!
40-
}
41-
4238
type User implements Node {
4339
errorField: String
4440
id: ID!
@@ -47,6 +43,11 @@ type User implements Node {
4743
username: String!
4844
}
4945

46+
type Viewer {
47+
user: User
48+
data: SomeData!
49+
}
50+
5051
type SomeData {
5152
accountValue: String!
5253
}

src/HotChocolate/Fusion/test/CommandLine.Tests/__snapshots__/PackageHelperTests.Create_Subgraph_Package.snap

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Query {
2424
userById(id: ID!): User
2525
usersById(ids: [ID!]!): [User!]!
2626
errorField: String
27+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
2728
viewer: Viewer!
2829
}
2930

@@ -34,11 +35,6 @@ type Mutation {
3435
"The `Date` scalar represents an ISO-8601 compliant date type."
3536
scalar Date
3637

37-
type Viewer {
38-
user: User
39-
data: SomeData!
40-
}
41-
4238
type User implements Node {
4339
errorField: String
4440
id: ID!
@@ -47,6 +43,11 @@ type User implements Node {
4743
username: String!
4844
}
4945

46+
type Viewer {
47+
user: User
48+
data: SomeData!
49+
}
50+
5051
type SomeData {
5152
accountValue: String!
5253
}

src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ type Query {
2222
@resolver(subgraph: "Reviews", select: "{ reviewOrAuthor }")
2323
reviews: [Review!]!
2424
@resolver(subgraph: "Reviews", select: "{ reviews }")
25+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
26+
@variable(subgraph: "Accounts", name: "first", argument: "first")
27+
@variable(subgraph: "Accounts", name: "second", argument: "second")
28+
@resolver(subgraph: "Accounts", select: "{ testWithTwoArgumentsDifferingNullability(first: $first, second: $second) }", arguments: [ { name: "first", type: "Int!" }, { name: "second", type: "Int" } ])
2529
userById(id: ID!): User
2630
@variable(subgraph: "Accounts", name: "id", argument: "id")
2731
@resolver(subgraph: "Accounts", select: "{ userById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ])

src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews2_Products_With_Nodes.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ type Query {
4343
@resolver(subgraph: "Reviews2", select: "{ reviewOrAuthor }")
4444
reviews: [Review!]!
4545
@resolver(subgraph: "Reviews2", select: "{ reviews }")
46+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
47+
@variable(subgraph: "Accounts", name: "first", argument: "first")
48+
@variable(subgraph: "Accounts", name: "second", argument: "second")
49+
@resolver(subgraph: "Accounts", select: "{ testWithTwoArgumentsDifferingNullability(first: $first, second: $second) }", arguments: [ { name: "first", type: "Int!" }, { name: "second", type: "Int" } ])
4650
topProducts(first: Int!): [Product!]!
4751
@variable(subgraph: "Products", name: "first", argument: "first")
4852
@resolver(subgraph: "Products", select: "{ topProducts(first: $first) }", arguments: [ { name: "first", type: "Int!" } ])

src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Infer_Patterns.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ type Query {
2222
@resolver(subgraph: "Reviews", select: "{ reviewOrAuthor }")
2323
reviews: [Review!]!
2424
@resolver(subgraph: "Reviews", select: "{ reviews }")
25+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
26+
@variable(subgraph: "Accounts", name: "first", argument: "first")
27+
@variable(subgraph: "Accounts", name: "second", argument: "second")
28+
@resolver(subgraph: "Accounts", select: "{ testWithTwoArgumentsDifferingNullability(first: $first, second: $second) }", arguments: [ { name: "first", type: "Int!" }, { name: "second", type: "Int" } ])
2529
userById(id: ID!): User
2630
@variable(subgraph: "Accounts", name: "id", argument: "id")
2731
@resolver(subgraph: "Accounts", select: "{ userById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ])

src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Products.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ type Query {
3232
@resolver(subgraph: "Reviews", select: "{ reviewOrAuthor }")
3333
reviews: [Review!]!
3434
@resolver(subgraph: "Reviews", select: "{ reviews }")
35+
testWithTwoArgumentsDifferingNullability(first: Int! second: Int): Int
36+
@variable(subgraph: "Accounts", name: "first", argument: "first")
37+
@variable(subgraph: "Accounts", name: "second", argument: "second")
38+
@resolver(subgraph: "Accounts", select: "{ testWithTwoArgumentsDifferingNullability(first: $first, second: $second) }", arguments: [ { name: "first", type: "Int!" }, { name: "second", type: "Int" } ])
3539
topProducts(first: Int!): [Product!]!
3640
@variable(subgraph: "Products", name: "first", argument: "first")
3741
@resolver(subgraph: "Products", select: "{ topProducts(first: $first) }", arguments: [ { name: "first", type: "Int!" } ])

0 commit comments

Comments
 (0)