Skip to content

Commit 24c8be8

Browse files
Fixed pattern entity enricher for batch resolvers. (#6956)
Co-authored-by: Michael Staib <[email protected]>
1 parent 866fdd3 commit 24c8be8

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/HotChocolate/Fusion/src/Composition/Pipeline/Enrichers/PatternEntityEnricher.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,13 @@ private static bool TryResolveBatchKeyArgument(
248248
{
249249
if (keyArgument.Type.IsListType() && !keyArgument.ContainsIsDirective())
250250
{
251-
return keyArgument.Type.Equals(keyField.Type.InnerType(), TypeComparison.Structural);
251+
var argumentType = keyArgument.Type;
252+
if (argumentType.Kind is TypeKind.NonNull)
253+
{
254+
argumentType = argumentType.InnerType();
255+
}
256+
257+
return argumentType.InnerType().Equals(keyField.Type, TypeComparison.Structural);
252258
}
253259

254260
keyArgument = null;
@@ -261,7 +267,13 @@ private static bool TryResolveBatchKeyArgument(
261267

262268
if (keyArgument.Type.IsListType() && !keyArgument.ContainsIsDirective())
263269
{
264-
return keyArgument.Type.Equals(keyField.Type.InnerType(), TypeComparison.Structural);
270+
var argumentType = keyArgument.Type;
271+
if (argumentType.Kind is TypeKind.NonNull)
272+
{
273+
argumentType = argumentType.InnerType();
274+
}
275+
276+
return argumentType.InnerType().Equals(keyField.Type, TypeComparison.Structural);
265277
}
266278

267279
keyArgument = null;
@@ -288,11 +300,15 @@ private static bool TryResolveBatchKeyArgument(
288300
}
289301
}
290302

291-
if (keyArgument?.Type.IsListType() is true &&
292-
keyArgument.Type.InnerType().Equals(keyField.Type, TypeComparison.Structural) &&
293-
!keyArgument.ContainsIsDirective())
303+
if (keyArgument?.Type.IsListType() is true && !keyArgument.ContainsIsDirective())
294304
{
295-
return true;
305+
var argumentType = keyArgument.Type;
306+
if (argumentType.Kind is TypeKind.NonNull)
307+
{
308+
argumentType = argumentType.InnerType();
309+
}
310+
311+
return argumentType.InnerType().Equals(keyField.Type, TypeComparison.Structural);
296312
}
297313

298314
keyArgument = null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type User implements Node
9292
@variable(subgraph: "Reviews", name: "User_id", select: "id")
9393
@resolver(subgraph: "Reviews", select: "{ authorById(id: $User_id) }", arguments: [ { name: "User_id", type: "ID!" } ])
9494
@resolver(subgraph: "Accounts", select: "{ userById(id: $User_id) }", arguments: [ { name: "User_id", type: "ID!" } ])
95-
@resolver(subgraph: "Accounts", select: "{ nodes(ids: $User_id) { ... on User { ... User } } }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH")
95+
@resolver(subgraph: "Accounts", select: "{ usersById(ids: $User_id) }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH")
9696
@resolver(subgraph: "Reviews", select: "{ nodes(ids: $User_id) { ... on User { ... User } } }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") {
9797
birthdate: Date!
9898
@source(subgraph: "Accounts")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ type UploadProductPicturePayload {
155155
type User implements Node
156156
@variable(subgraph: "Accounts", name: "User_id", select: "id")
157157
@resolver(subgraph: "Accounts", select: "{ userById(id: $User_id) }", arguments: [ { name: "User_id", type: "ID!" } ])
158-
@resolver(subgraph: "Accounts", select: "{ nodes(ids: $User_id) { ... on User { ... User } } }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") {
158+
@resolver(subgraph: "Accounts", select: "{ usersById(ids: $User_id) }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") {
159159
birthdate: Date!
160160
@source(subgraph: "Accounts")
161161
id: ID!

src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/RequireTests.Require_Scalar_Arguments_No_Overloads.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ type UploadProductPicturePayload {
175175
type User implements Node
176176
@variable(subgraph: "Accounts", name: "User_id", select: "id")
177177
@resolver(subgraph: "Accounts", select: "{ userById(id: $User_id) }", arguments: [ { name: "User_id", type: "ID!" } ])
178-
@resolver(subgraph: "Accounts", select: "{ nodes(ids: $User_id) { ... on User { ... User } } }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") {
178+
@resolver(subgraph: "Accounts", select: "{ usersById(ids: $User_id) }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") {
179179
birthdate: Date!
180180
@source(subgraph: "Accounts")
181181
id: ID!

0 commit comments

Comments
 (0)