Skip to content

Commit

Permalink
Add Fusion composition tests for @deprecated merging
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Sep 29, 2023
1 parent 9da664a commit 9cf368a
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
""");
}
Original file line number Diff line number Diff line change
@@ -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!
}
Original file line number Diff line number Diff line change
@@ -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!
}
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 9cf368a

Please sign in to comment.