From 2ccafae5ca0f07347a1caada3aadf4ffe7f99f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20W=C3=B6rg=C3=B6tter?= Date: Fri, 1 Mar 2024 23:44:45 +0100 Subject: [PATCH] fix: pattern entity enricher for batch resolvers --- .../Enrichers/PatternEntityEnricher.cs | 28 +++++++++++++++---- ...ccounts_And_Reviews_Infer_Patterns.graphql | 2 +- ...ews_Products_AutoCompose_With_Node.graphql | 2 +- ...uire_Scalar_Arguments_No_Overloads.graphql | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/HotChocolate/Fusion/src/Composition/Pipeline/Enrichers/PatternEntityEnricher.cs b/src/HotChocolate/Fusion/src/Composition/Pipeline/Enrichers/PatternEntityEnricher.cs index 36206345e2e..af13c033434 100644 --- a/src/HotChocolate/Fusion/src/Composition/Pipeline/Enrichers/PatternEntityEnricher.cs +++ b/src/HotChocolate/Fusion/src/Composition/Pipeline/Enrichers/PatternEntityEnricher.cs @@ -248,7 +248,13 @@ private static bool TryResolveBatchKeyArgument( { if (keyArgument.Type.IsListType() && !keyArgument.ContainsIsDirective()) { - return keyArgument.Type.Equals(keyField.Type.InnerType(), TypeComparison.Structural); + var argumentType = keyArgument.Type; + if (argumentType.Kind is TypeKind.NonNull) + { + argumentType = argumentType.InnerType(); + } + + return argumentType.InnerType().Equals(keyField.Type, TypeComparison.Structural); } keyArgument = null; @@ -261,7 +267,13 @@ private static bool TryResolveBatchKeyArgument( if (keyArgument.Type.IsListType() && !keyArgument.ContainsIsDirective()) { - return keyArgument.Type.Equals(keyField.Type.InnerType(), TypeComparison.Structural); + var argumentType = keyArgument.Type; + if (argumentType.Kind is TypeKind.NonNull) + { + argumentType = argumentType.InnerType(); + } + + return argumentType.InnerType().Equals(keyField.Type, TypeComparison.Structural); } keyArgument = null; @@ -288,11 +300,15 @@ private static bool TryResolveBatchKeyArgument( } } - if (keyArgument?.Type.IsListType() is true && - keyArgument.Type.InnerType().Equals(keyField.Type, TypeComparison.Structural) && - !keyArgument.ContainsIsDirective()) + if (keyArgument?.Type.IsListType() is true && !keyArgument.ContainsIsDirective()) { - return true; + var argumentType = keyArgument.Type; + if (argumentType.Kind is TypeKind.NonNull) + { + argumentType = argumentType.InnerType(); + } + + return argumentType.InnerType().Equals(keyField.Type, TypeComparison.Structural); } keyArgument = null; diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Infer_Patterns.graphql b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Infer_Patterns.graphql index 377465c1f21..92919eb3840 100644 --- a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Infer_Patterns.graphql +++ b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Infer_Patterns.graphql @@ -92,7 +92,7 @@ type User implements Node @variable(subgraph: "Reviews", name: "User_id", select: "id") @resolver(subgraph: "Reviews", select: "{ authorById(id: $User_id) }", arguments: [ { name: "User_id", type: "ID!" } ]) @resolver(subgraph: "Accounts", select: "{ userById(id: $User_id) }", arguments: [ { name: "User_id", type: "ID!" } ]) - @resolver(subgraph: "Accounts", select: "{ nodes(ids: $User_id) { ... on User { ... User } } }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") + @resolver(subgraph: "Accounts", select: "{ usersById(ids: $User_id) }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") @resolver(subgraph: "Reviews", select: "{ nodes(ids: $User_id) { ... on User { ... User } } }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") { birthdate: Date! @source(subgraph: "Accounts") diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Products_AutoCompose_With_Node.graphql b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Products_AutoCompose_With_Node.graphql index 63e92ba27fb..f4e706fe4d8 100644 --- a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Products_AutoCompose_With_Node.graphql +++ b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DemoIntegrationTests.Accounts_And_Reviews_Products_AutoCompose_With_Node.graphql @@ -155,7 +155,7 @@ type UploadProductPicturePayload { type User implements Node @variable(subgraph: "Accounts", name: "User_id", select: "id") @resolver(subgraph: "Accounts", select: "{ userById(id: $User_id) }", arguments: [ { name: "User_id", type: "ID!" } ]) - @resolver(subgraph: "Accounts", select: "{ nodes(ids: $User_id) { ... on User { ... User } } }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") { + @resolver(subgraph: "Accounts", select: "{ usersById(ids: $User_id) }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") { birthdate: Date! @source(subgraph: "Accounts") id: ID! diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/RequireTests.Require_Scalar_Arguments_No_Overloads.graphql b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/RequireTests.Require_Scalar_Arguments_No_Overloads.graphql index 6cb3360091d..21b6ef99409 100644 --- a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/RequireTests.Require_Scalar_Arguments_No_Overloads.graphql +++ b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/RequireTests.Require_Scalar_Arguments_No_Overloads.graphql @@ -175,7 +175,7 @@ type UploadProductPicturePayload { type User implements Node @variable(subgraph: "Accounts", name: "User_id", select: "id") @resolver(subgraph: "Accounts", select: "{ userById(id: $User_id) }", arguments: [ { name: "User_id", type: "ID!" } ]) - @resolver(subgraph: "Accounts", select: "{ nodes(ids: $User_id) { ... on User { ... User } } }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") { + @resolver(subgraph: "Accounts", select: "{ usersById(ids: $User_id) }", arguments: [ { name: "User_id", type: "[ID!]!" } ], kind: "BATCH") { birthdate: Date! @source(subgraph: "Accounts") id: ID!