From 9cf368a429f0bfae73c57857733f427587142fe8 Mon Sep 17 00:00:00 2001 From: tobias-tengler <45513122+tobias-tengler@users.noreply.github.com> Date: Fri, 29 Sep 2023 21:53:18 +0200 Subject: [PATCH] Add Fusion composition tests for @deprecated merging --- .../DeprecationMergeTests.cs | 136 ++++++++++++++++++ ..._Output_Field_Argument_Deprecation.graphql | 34 +++++ ...ge_Entity_Output_Field_Deprecation.graphql | 33 +++++ ...Tests.Merge_Enum_Value_Deprecation.graphql | 20 +++ ..._Output_Field_Argument_Deprecation.graphql | 21 +++ ...sts.Merge_Output_Field_Deprecation.graphql | 20 +++ 6 files changed, 264 insertions(+) create mode 100644 src/HotChocolate/Fusion/test/Composition.Tests/DeprecationMergeTests.cs create mode 100644 src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Entity_Output_Field_Argument_Deprecation.graphql create mode 100644 src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Entity_Output_Field_Deprecation.graphql create mode 100644 src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Enum_Value_Deprecation.graphql create mode 100644 src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Output_Field_Argument_Deprecation.graphql create mode 100644 src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Output_Field_Deprecation.graphql diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/DeprecationMergeTests.cs b/src/HotChocolate/Fusion/test/Composition.Tests/DeprecationMergeTests.cs new file mode 100644 index 00000000000..ae110337a64 --- /dev/null +++ b/src/HotChocolate/Fusion/test/Composition.Tests/DeprecationMergeTests.cs @@ -0,0 +1,136 @@ +using Xunit.Abstractions; + +namespace HotChocolate.Fusion.Composition; + +public class DeprecationMergeTests(ITestOutputHelper output) : CompositionTestBase(output) +{ + [Fact] + public async Task Merge_Entity_Output_Field_Deprecation() + => await Succeed( + """ + type Query { + brandById(id: ID!): Brand + } + + type Brand implements Node { + id: ID! + name: String! @deprecated(reason: "Some reason") + } + + interface Node { + id: ID! + } + """, + """ + type Query { + brandById(id: ID!): Brand + } + + type Brand implements Node { + id: ID! + newName: String! + } + + interface Node { + id: ID! + } + """); + + [Fact] + public async Task Merge_Entity_Output_Field_Argument_Deprecation() + => await Succeed( + """ + type Query { + brandById(id: ID!): Brand + } + + type Brand implements Node { + id: ID! + name(includeFirstName: Boolean @deprecated(reason: "Some reason")): String! + } + + interface Node { + id: ID! + } + """, + """ + type Query { + brandById(id: ID!): Brand + } + + type Brand implements Node { + id: ID! + name(includeFirstName: Boolean): String! + } + + interface Node { + id: ID! + } + """); + + [Fact] + public async Task Merge_Output_Field_Deprecation() + => await Succeed( + """ + type Query { + brand: Brand + } + + type Brand { + name: String! @deprecated(reason: "Some reason") + } + """, + """ + type Query { + brand: Brand + } + + type Brand { + newName: String! + } + """); + + [Fact] + public async Task Merge_Output_Field_Argument_Deprecation() + => await Succeed( + """ + type Query { + brand: Brand + } + + type Brand { + name(includeFirstName: Boolean @deprecated(reason: "Some reason")): String! + } + """, + """ + type Query { + brand: Brand + } + + type Brand { + name(includeFirstName: Boolean): String! + } + """); + + [Fact] + public async Task Merge_Enum_Value_Deprecation() + => await Succeed( + """ + type Query { + value: OrderStatus + } + + enum OrderStatus { + SENT_OUT @deprecated(reason: "Some reason") + } + """, + """ + type Query { + value: OrderStatus + } + + enum OrderStatus { + SHIPPED + } + """); +} diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Entity_Output_Field_Argument_Deprecation.graphql b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Entity_Output_Field_Argument_Deprecation.graphql new file mode 100644 index 00000000000..cd91ddf7af7 --- /dev/null +++ b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Entity_Output_Field_Argument_Deprecation.graphql @@ -0,0 +1,34 @@ +schema + @fusion(version: 1) + @transport(subgraph: "A", location: "https:\/\/localhost:5001\/graphql", kind: "HTTP") + @transport(subgraph: "B", location: "https:\/\/localhost:5002\/graphql", kind: "HTTP") { + query: Query +} + +type Query { + brandById(id: ID!): Brand + @variable(subgraph: "A", name: "id", argument: "id") + @resolver(subgraph: "A", select: "{ brandById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ]) + @variable(subgraph: "B", name: "id", argument: "id") + @resolver(subgraph: "B", select: "{ brandById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ]) +} + +type Brand implements Node + @variable(subgraph: "A", name: "Brand_id", select: "id") + @variable(subgraph: "B", name: "Brand_id", select: "id") + @resolver(subgraph: "A", select: "{ brandById(id: $Brand_id) }", arguments: [ { name: "Brand_id", type: "ID!" } ]) + @resolver(subgraph: "B", select: "{ brandById(id: $Brand_id) }", arguments: [ { name: "Brand_id", type: "ID!" } ]) { + id: ID! + @source(subgraph: "A") + @source(subgraph: "B") + name(includeFirstName: Boolean + @deprecated(reason: "Some reason")): String! + @source(subgraph: "A") + @variable(subgraph: "A", name: "includeFirstName", argument: "includeFirstName") + @source(subgraph: "B") + @variable(subgraph: "B", name: "includeFirstName", argument: "includeFirstName") +} + +interface Node { + id: ID! +} \ No newline at end of file diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Entity_Output_Field_Deprecation.graphql b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Entity_Output_Field_Deprecation.graphql new file mode 100644 index 00000000000..7d21b665113 --- /dev/null +++ b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Entity_Output_Field_Deprecation.graphql @@ -0,0 +1,33 @@ +schema + @fusion(version: 1) + @transport(subgraph: "A", location: "https:\/\/localhost:5001\/graphql", kind: "HTTP") + @transport(subgraph: "B", location: "https:\/\/localhost:5002\/graphql", kind: "HTTP") { + query: Query +} + +type Query { + brandById(id: ID!): Brand + @variable(subgraph: "A", name: "id", argument: "id") + @resolver(subgraph: "A", select: "{ brandById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ]) + @variable(subgraph: "B", name: "id", argument: "id") + @resolver(subgraph: "B", select: "{ brandById(id: $id) }", arguments: [ { name: "id", type: "ID!" } ]) +} + +type Brand implements Node + @variable(subgraph: "A", name: "Brand_id", select: "id") + @variable(subgraph: "B", name: "Brand_id", select: "id") + @resolver(subgraph: "A", select: "{ brandById(id: $Brand_id) }", arguments: [ { name: "Brand_id", type: "ID!" } ]) + @resolver(subgraph: "B", select: "{ brandById(id: $Brand_id) }", arguments: [ { name: "Brand_id", type: "ID!" } ]) { + id: ID! + @source(subgraph: "A") + @source(subgraph: "B") + name: String! + @source(subgraph: "A") + @deprecated(reason: "Some reason") + newName: String! + @source(subgraph: "B") +} + +interface Node { + id: ID! +} \ No newline at end of file diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Enum_Value_Deprecation.graphql b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Enum_Value_Deprecation.graphql new file mode 100644 index 00000000000..2eb1aef33dc --- /dev/null +++ b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Enum_Value_Deprecation.graphql @@ -0,0 +1,20 @@ +schema + @fusion(version: 1) + @transport(subgraph: "A", location: "https:\/\/localhost:5001\/graphql", kind: "HTTP") + @transport(subgraph: "B", location: "https:\/\/localhost:5002\/graphql", kind: "HTTP") { + query: Query +} + +type Query { + value: OrderStatus + @resolver(subgraph: "A", select: "{ value }") + @resolver(subgraph: "B", select: "{ value }") +} + +enum OrderStatus { + SENT_OUT + @source(subgraph: "A") + @deprecated(reason: "Some reason") + SHIPPED + @source(subgraph: "B") +} \ No newline at end of file diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Output_Field_Argument_Deprecation.graphql b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Output_Field_Argument_Deprecation.graphql new file mode 100644 index 00000000000..f0f33899875 --- /dev/null +++ b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Output_Field_Argument_Deprecation.graphql @@ -0,0 +1,21 @@ +schema + @fusion(version: 1) + @transport(subgraph: "A", location: "https:\/\/localhost:5001\/graphql", kind: "HTTP") + @transport(subgraph: "B", location: "https:\/\/localhost:5002\/graphql", kind: "HTTP") { + query: Query +} + +type Query { + brand: Brand + @resolver(subgraph: "A", select: "{ brand }") + @resolver(subgraph: "B", select: "{ brand }") +} + +type Brand { + name(includeFirstName: Boolean + @deprecated(reason: "Some reason")): String! + @source(subgraph: "A") + @variable(subgraph: "A", name: "includeFirstName", argument: "includeFirstName") + @source(subgraph: "B") + @variable(subgraph: "B", name: "includeFirstName", argument: "includeFirstName") +} \ No newline at end of file diff --git a/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Output_Field_Deprecation.graphql b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Output_Field_Deprecation.graphql new file mode 100644 index 00000000000..449081c98de --- /dev/null +++ b/src/HotChocolate/Fusion/test/Composition.Tests/__snapshots__/DeprecationMergeTests.Merge_Output_Field_Deprecation.graphql @@ -0,0 +1,20 @@ +schema + @fusion(version: 1) + @transport(subgraph: "A", location: "https:\/\/localhost:5001\/graphql", kind: "HTTP") + @transport(subgraph: "B", location: "https:\/\/localhost:5002\/graphql", kind: "HTTP") { + query: Query +} + +type Query { + brand: Brand + @resolver(subgraph: "A", select: "{ brand }") + @resolver(subgraph: "B", select: "{ brand }") +} + +type Brand { + name: String! + @source(subgraph: "A") + @deprecated(reason: "Some reason") + newName: String! + @source(subgraph: "B") +} \ No newline at end of file