Skip to content

Commit

Permalink
Merge branch 'main' into mst/tag-nullability-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Oct 3, 2023
2 parents e3e28c1 + ffd03ea commit fb1febe
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public static DirectiveNode CreateNode(string? reason = null)

var arguments = reason is null
? Array.Empty<ArgumentNode>()
: new[] { new ArgumentNode(DeprecatedDirectiveType.Names.Reason, reason) };
: new[] { new ArgumentNode(WellKnownDirectives.DeprecationReasonArgument, reason) };

return new DirectiveNode(
null,
new NameNode(DeprecatedDirectiveType.Names.Deprecated),
new NameNode(WellKnownDirectives.Deprecated),
arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override void Configure(
IDirectiveTypeDescriptor<DeprecatedDirective> descriptor)
{
descriptor
.Name(Names.Deprecated)
.Name(WellKnownDirectives.Deprecated)
.Description(TypeResources.DeprecatedDirectiveType_TypeDescription)
.Location(DirectiveLocation.FieldDefinition)
.Location(DirectiveLocation.ArgumentDefinition)
Expand All @@ -25,15 +25,9 @@ protected override void Configure(

descriptor
.Argument(t => t.Reason)
.Name(Names.Reason)
.Name(WellKnownDirectives.DeprecationReasonArgument)
.Description(TypeResources.DeprecatedDirectiveType_ReasonDescription)
.Type<StringType>()
.DefaultValue(WellKnownDirectives.DeprecationDefaultReason);
}

public static class Names
{
public const string Deprecated = "deprecated";
public const string Reason = "reason";
}
}
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")
}
Loading

0 comments on commit fb1febe

Please sign in to comment.