Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print @deprecated in HotChocolate.Skimmed.SchemaFormatter #6565

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading