Skip to content

Commit

Permalink
Fixed Tag Directive
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Apr 16, 2024
1 parent a2c1f1a commit 056b235
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
16 changes: 15 additions & 1 deletion src/HotChocolate/Core/src/Types/Types/Directives/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ namespace HotChocolate.Types;
DirectiveLocation.Schema,
IsRepeatable = true)]
[TagDirectiveConfig]
[GraphQLDescription(
"""
The @tag directive is used to apply arbitrary string
metadata to a schema location. Custom tooling can use
this metadata during any step of the schema delivery flow,
including composition, static analysis, and documentation.
interface Book {
id: ID! @tag(name: "your-value")
title: String!
author: String!
}
""")]
public sealed class Tag
{
/// <summary>
Expand All @@ -61,5 +74,6 @@ public Tag(string name)
/// <summary>
/// The name of the tag.
/// </summary>
[GraphQLDescription("The name of the tag.")]
public string Name { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,10 @@ namespace HotChocolate.Types;
internal sealed class TagDirectiveConfigAttribute : DirectiveTypeDescriptorAttribute
{
protected override void OnConfigure(
IDescriptorContext context,
IDirectiveTypeDescriptor descriptor,
IDescriptorContext context,
IDirectiveTypeDescriptor descriptor,
Type type)
{
descriptor.Description(
"""
The @tag directive is used to apply arbitrary string
metadata to a schema location. Custom tooling can use
this metadata during any step of the schema delivery flow,
including composition, static analysis, and documentation.

interface Book {
id: ID! @tag(name: "your-value")
title: String!
author: String!
}
""");

descriptor
.Argument("name")
.Type<NonNullType<StringType>>()
.Description("The name of the tag.");

if (context.ContextData.TryGetValue(WellKnownContextData.TagOptions, out var value) &&
value is TagOptions { Mode: TagMode.ApolloFederation, })
{
Expand All @@ -46,4 +27,4 @@ interface Book {
DirectiveLocation.EnumValue;
}
}
}
}

0 comments on commit 056b235

Please sign in to comment.