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

Added tag directive refinements. #6601

Merged
merged 2 commits into from
Oct 13, 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 @@ -28,7 +28,7 @@ public static IRequestExecutorBuilder AddApolloFederation(
{
throw new ArgumentNullException(nameof(builder));
}

return builder.ConfigureSchema(s => ApolloFederationSchemaBuilderExtensions.AddApolloFederation(s));
return builder.ConfigureSchema(s => s.AddApolloFederation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class ApolloFederationSchemaBuilderExtensions
/// <exception cref="ArgumentNullException">
/// The <paramref name="builder"/> is <c>null</c>.
/// </exception>
public static ISchemaBuilder AddApolloFederation(
internal static ISchemaBuilder AddApolloFederation(
this ISchemaBuilder builder)
{
if (builder is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using HotChocolate.Types.Descriptors.Definitions;
using static HotChocolate.ApolloFederation.ThrowHelper;
using static HotChocolate.ApolloFederation.Constants.WellKnownContextData;
using static HotChocolate.Types.TagHelper;

namespace HotChocolate.ApolloFederation;

Expand Down Expand Up @@ -53,6 +54,7 @@ internal override void InitializeContext(
{
_context = context;
_typeInspector = context.TypeInspector;
ModifyOptions(context, o => o.Mode = TagMode.ApolloFederation);
}

public override void OnAfterInitialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
"Used to annotate the required input fieldset from a base type for a resolver."
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ extend type User @key(fields: "email") {
totalProductsCreated: Int @external
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
"Used to annotate the required input fieldset from a base type for a resolver."
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ extend type User @key(fields: "email") {
totalProductsCreated: Int @external
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
"Used to annotate the required input fieldset from a base type for a resolver."
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
"Used to annotate the required input fieldset from a base type for a resolver."
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
"Used to annotate the required input fieldset from a base type for a resolver."
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
"Used to annotate the required input fieldset from a base type for a resolver."
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
"Used to annotate the required input fieldset from a base type for a resolver."
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
"Used to annotate the required input fieldset from a base type for a resolver."
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION

"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema."
scalar _Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ type User @key(fields: "id") {
address: Address! @provides(fields: "zipcode")
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type TestType @key(fields: "id") {
name: String!
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ interface iTestType @key(fields: "id") {
external: String! @external
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ interface iTestType @key(fields: "id") {
external: String! @external
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ type QueryRootOfProduct {
entity(id: Int!): Product!
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
matchCode: String
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
matchCode: String!
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ type Query {
address(id: Int!): Address!
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ type Query {
address: Address!
}

directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,9 @@ public static class WellKnownContextData
/// The key to access the true nullability flag on the execution context.
/// </summary>
public const string EnableTrueNullability = "HotChocolate.Types.EnableTrueNullability";

/// <summary>
/// The key to access the tag options object.
/// </summary>
public const string TagOptions = "HotChocolate.Types.TagOptions";
}
5 changes: 3 additions & 2 deletions src/HotChocolate/Core/src/Types/Types/Directives/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace HotChocolate.Types;
DirectiveLocation.EnumValue |
DirectiveLocation.Schema,
IsRepeatable = true)]
[TagDirectiveConfig]
public sealed class Tag
{
/// <summary>
Expand All @@ -56,9 +57,9 @@ public Tag(string name)

Name = name;
}

/// <summary>
/// The name of the tag.
/// </summary>
public string Name { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#nullable enable
using System;
using HotChocolate.Types.Descriptors;

namespace HotChocolate.Types;

internal sealed class TagDirectiveConfigAttribute : DirectiveTypeDescriptorAttribute
{
protected override void OnConfigure(
IDescriptorContext context,
IDirectiveTypeDescriptor descriptor,
Type type)
{
if (context.ContextData.TryGetValue(WellKnownContextData.TagOptions, out var value) &&
value is TagOptions { Mode: TagMode.ApolloFederation })
{
descriptor.Extend().Definition.Locations =
DirectiveLocation.Object |
DirectiveLocation.Interface |
DirectiveLocation.Union |
DirectiveLocation.InputObject |
DirectiveLocation.Enum |
DirectiveLocation.Scalar |
DirectiveLocation.FieldDefinition |
DirectiveLocation.InputFieldDefinition |
DirectiveLocation.ArgumentDefinition |
DirectiveLocation.EnumValue;
}
}
}
24 changes: 24 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Directives/TagHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#nullable enable
using System;
using HotChocolate.Types.Descriptors;

namespace HotChocolate.Types;

internal static class TagHelper
{
public static void ModifyOptions(IDescriptorContext context, Action<TagOptions> configure)
{
TagOptions? options = null;

if (context.ContextData.TryGetValue(WellKnownContextData.TagOptions, out var value) &&
value is TagOptions opt)
{
options = opt;
}

options ??= new TagOptions();
context.ContextData[WellKnownContextData.TagOptions] = options;
configure(options);
}

}
7 changes: 7 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Directives/TagMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace HotChocolate.Types;

internal enum TagMode
{
GraphQLFusion,
ApolloFederation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#nullable enable
namespace HotChocolate.Types;

internal sealed class TagOptions
{
public TagMode Mode { get; set; } = TagMode.GraphQLFusion;
}
2 changes: 0 additions & 2 deletions temp.txt

This file was deleted.

Loading