Skip to content

Commit

Permalink
Fixed name convention interference with the introspection types. (#2588)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Nov 16, 2020
1 parent b7ff8fa commit b2877e3
Show file tree
Hide file tree
Showing 16 changed files with 438 additions and 298 deletions.
Expand Up @@ -66,7 +66,7 @@ IObjectFieldDescriptor Type<TOutputType>()
Type resultType);

IObjectFieldDescriptor ResolveWith<TResolver>(
Expression<Func<TResolver, object>> propertyOrMethod);
Expression<Func<TResolver, object?>> propertyOrMethod);

IObjectFieldDescriptor ResolveWith(MemberInfo propertyOrMethod);

Expand Down
66 changes: 45 additions & 21 deletions src/HotChocolate/Core/src/Types/Types/Introspection/__Directive.cs
@@ -1,53 +1,63 @@
#pragma warning disable IDE1006 // Naming Styles
using System.Collections.Generic;
using HotChocolate.Properties;
using HotChocolate.Resolvers;

#nullable enable

namespace HotChocolate.Types.Introspection
{
[Introspection]
internal sealed class __Directive
: ObjectType
internal sealed class __Directive : ObjectType
{
protected override void Configure(
IObjectTypeDescriptor descriptor)
{
descriptor.Name("__Directive");

descriptor.Description(TypeResources.Directive_Description);
descriptor
.Name(Names.__Directive)
.Description(TypeResources.Directive_Description);

descriptor.Field("name")
descriptor
.Field(Names.Name)
.Type<NonNullType<StringType>>()
.Resolver(c => c.Parent<DirectiveType>().Name);
.Resolve(c => c.Parent<DirectiveType>().Name);

descriptor.Field("description")
descriptor
.Field(Names.Description)
.Type<StringType>()
.Resolver(c => c.Parent<DirectiveType>().Description);
.Resolve(c => c.Parent<DirectiveType>().Description);

descriptor.Field("isRepeatable")
descriptor
.Field(Names.IsRepeatable)
.Type<BooleanType>()
.Resolver(c => c.Parent<DirectiveType>().IsRepeatable);
.Resolve(c => c.Parent<DirectiveType>().IsRepeatable);

descriptor.Field("locations")
descriptor
.Field(Names.Locations)
.Type<NonNullType<ListType<NonNullType<__DirectiveLocation>>>>()
.Resolver(c => c.Parent<DirectiveType>().Locations);
.Resolve(c => c.Parent<DirectiveType>().Locations);

descriptor.Field("args")
descriptor
.Field(Names.Args)
.Type<NonNullType<ListType<NonNullType<__InputValue>>>>()
.Resolver(c => c.Parent<DirectiveType>().Arguments);
.Resolve(c => c.Parent<DirectiveType>().Arguments);

descriptor.Field("onOperation")
descriptor
.Field(Names.OnOperation)
.Type<NonNullType<BooleanType>>()
.Resolver(c => GetOnOperation(c))
.Resolve(c => GetOnOperation(c))
.Deprecated(TypeResources.Directive_UseLocation);

descriptor.Field("onFragment")
descriptor
.Field(Names.OnFragment)
.Type<NonNullType<BooleanType>>()
.Resolver(c => GetOnFragment(c))
.Resolve(c => GetOnFragment(c))
.Deprecated(TypeResources.Directive_UseLocation);

descriptor.Field("onField")
descriptor
.Field(Names.OnField)
.Type<NonNullType<BooleanType>>()
.Resolver(c => GetOnField(c))
.Resolve(c => GetOnField(c))
.Deprecated(TypeResources.Directive_UseLocation);
}

Expand Down Expand Up @@ -78,5 +88,19 @@ private static bool GetOnField(IResolverContext context)

return locations.Contains(DirectiveLocation.Field);
}

public static class Names
{
public const string __Directive = "__Directive";
public const string Name = "name";
public const string Description = "description";
public const string IsRepeatable = "isRepeatable";
public const string Locations = "locations";
public const string Args = "args";
public const string OnOperation = "onOperation";
public const string OnFragment = "onFragment";
public const string OnField = "onField";
}
}
}
#pragma warning restore IDE1006 // Naming Styles
@@ -1,86 +1,122 @@
#pragma warning disable IDE1006 // Naming Styles
using HotChocolate.Properties;
using Lang = HotChocolate.Language.DirectiveLocation;

#nullable enable
namespace HotChocolate.Types.Introspection
{
[Introspection]
#pragma warning disable IDE1006 // Naming Styles
internal sealed class __DirectiveLocation
#pragma warning restore IDE1006 // Naming Styles
: EnumType<DirectiveLocation>
internal sealed class __DirectiveLocation : EnumType<DirectiveLocation>
{
protected override void Configure(IEnumTypeDescriptor<DirectiveLocation> descriptor)
{
descriptor.Name("__DirectiveLocation");

descriptor.Description(
TypeResources.DirectiveLocation_Description);

descriptor.Item(DirectiveLocation.Query)
descriptor
.Name(Names.__DirectiveLocation)
.Description(TypeResources.DirectiveLocation_Description)
// Introspection types must always be bound explicitly so that we
// do not get any interference with conventions.
.BindItems(BindingBehavior.Explicit);

descriptor
.Item(DirectiveLocation.Query)
.Name(Lang.Query.Value)
.Description(TypeResources.DirectiveLocation_Query);

descriptor.Item(DirectiveLocation.Mutation)
descriptor
.Item(DirectiveLocation.Mutation)
.Name(Lang.Mutation.Value)
.Description(TypeResources.DirectiveLocation_Mutation);

descriptor.Item(DirectiveLocation.Subscription)
descriptor
.Item(DirectiveLocation.Subscription)
.Name(Lang.Subscription.Value)
.Description(TypeResources.DirectiveLocation_Subscription);

descriptor.Item(DirectiveLocation.Field)
descriptor
.Item(DirectiveLocation.Field)
.Name(Lang.Field.Value)
.Description(TypeResources.DirectiveLocation_Field);

// TODO : Resources
descriptor.Item(DirectiveLocation.VariableDefinition)
.Name("VARIABLE_DEFINITION")
.Description("Location adjacent to a variable definition.");

descriptor.Item(DirectiveLocation.FragmentDefinition)
.Name("FRAGMENT_DEFINITION")
descriptor
.Item(DirectiveLocation.FragmentDefinition)
.Name(Lang.FragmentDefinition.Value)
.Description(TypeResources.DirectiveLocation_FragmentDefinition);

descriptor.Item(DirectiveLocation.FragmentSpread)
.Name("FRAGMENT_SPREAD")
descriptor
.Item(DirectiveLocation.FragmentSpread)
.Name(Lang.FragmentSpread.Value)
.Description(TypeResources.DirectiveLocation_FragmentSpread);

descriptor.Item(DirectiveLocation.InlineFragment)
.Name("INLINE_FRAGMENT")
descriptor
.Item(DirectiveLocation.InlineFragment)
.Name(Lang.InlineFragment.Value)
.Description(TypeResources.DirectiveLocation_InlineFragment);

descriptor.Item(DirectiveLocation.Schema)
descriptor
.Item(DirectiveLocation.VariableDefinition)
.Name(Lang.VariableDefinition.Value)
.Description("Location adjacent to a variable definition.");

descriptor
.Item(DirectiveLocation.Schema)
.Name(Lang.Schema.Value)
.Description(TypeResources.DirectiveLocation_Schema);

descriptor.Item(DirectiveLocation.Scalar)
descriptor
.Item(DirectiveLocation.Scalar)
.Name(Lang.Scalar.Value)
.Description(TypeResources.DirectiveLocation_Scalar);

descriptor.Item(DirectiveLocation.Object)
descriptor
.Item(DirectiveLocation.Object)
.Name(Lang.Object.Value)
.Description(TypeResources.DirectiveLocation_Object);

descriptor.Item(DirectiveLocation.FieldDefinition)
.Name("FIELD_DEFINITION")
descriptor
.Item(DirectiveLocation.FieldDefinition)
.Name(Lang.FieldDefinition.Value)
.Description(TypeResources.DirectiveLocation_FieldDefinition);

descriptor.Item(DirectiveLocation.ArgumentDefinition)
.Name("ARGUMENT_DEFINITION")
descriptor
.Item(DirectiveLocation.ArgumentDefinition)
.Name(Lang.ArgumentDefinition.Value)
.Description(TypeResources.DirectiveLocation_ArgumentDefinition);

descriptor.Item(DirectiveLocation.Interface)
descriptor
.Item(DirectiveLocation.Interface)
.Name(Lang.Interface.Value)
.Description(TypeResources.DirectiveLocation_Interface);

descriptor.Item(DirectiveLocation.Union)
descriptor
.Item(DirectiveLocation.Union)
.Name(Lang.Union.Value)
.Description(TypeResources.DirectiveLocation_Union);

descriptor.Item(DirectiveLocation.Enum)
descriptor
.Item(DirectiveLocation.Enum)
.Name(Lang.Enum.Value)
.Description(TypeResources.DirectiveLocation_Enum);

descriptor.Item(DirectiveLocation.EnumValue)
.Name("ENUM_VALUE")
descriptor
.Item(DirectiveLocation.EnumValue)
.Name(Lang.EnumValue.Value)
.Description(TypeResources.DirectiveLocation_EnumValue);

descriptor.Item(DirectiveLocation.InputObject)
.Name("INPUT_OBJECT")
descriptor
.Item(DirectiveLocation.InputObject)
.Name(Lang.InputObject.Value)
.Description(TypeResources.DirectiveLocation_InputObject);

descriptor.Item(DirectiveLocation.InputFieldDefinition)
.Name("INPUT_FIELD_DEFINITION")
descriptor
.Item(DirectiveLocation.InputFieldDefinition)
.Name(Lang.InputFieldDefinition.Value)
.Description(TypeResources.DirectiveLocation_InputFieldDefinition);
}

public static class Names
{
public const string __DirectiveLocation = "__DirectiveLocation";
}
}
}
#pragma warning restore IDE1006 // Naming Styles
45 changes: 31 additions & 14 deletions src/HotChocolate/Core/src/Types/Types/Introspection/__EnumValue.cs
@@ -1,32 +1,49 @@
#pragma warning disable IDE1006 // Naming Styles
using HotChocolate.Properties;

#nullable enable
namespace HotChocolate.Types.Introspection
{
[Introspection]
#pragma warning disable IDE1006 // Naming Styles
internal sealed class __EnumValue
#pragma warning restore IDE1006 // Naming Styles
: ObjectType<IEnumValue>
internal sealed class __EnumValue : ObjectType<IEnumValue>
{
protected override void Configure(
IObjectTypeDescriptor<IEnumValue> descriptor)
{
descriptor.Name("__EnumValue");

descriptor.Description(
TypeResources.EnumValue_Description);

descriptor.BindFields(BindingBehavior.Explicit);
descriptor
.Name(Names.__EnumValue)
.Description(TypeResources.EnumValue_Description)
// Introspection types must always be bound explicitly so that we
// do not get any interference with conventions.
.BindFields(BindingBehavior.Explicit);

descriptor.Field(c => c.Name)
descriptor
.Field(c => c.Name)
.Name(Names.Name)
.Type<NonNullType<StringType>>();

descriptor.Field(c => c.Description);
descriptor
.Field(c => c.Description)
.Name(Names.Description);

descriptor.Field(c => c.IsDeprecated)
descriptor
.Field(c => c.IsDeprecated)
.Name(Names.IsDeprecated)
.Type<NonNullType<BooleanType>>();

descriptor.Field(c => c.DeprecationReason);
descriptor
.Field(c => c.DeprecationReason)
.Name(Names.DeprecationReason);
}

public static class Names
{
public const string __EnumValue = "__EnumValue";
public const string Name = "name";
public const string Description = "description";
public const string IsDeprecated = "isDeprecated";
public const string DeprecationReason = "deprecationReason";
}
}
}
#pragma warning restore IDE1006 // Naming Styles

0 comments on commit b2877e3

Please sign in to comment.