Skip to content

Commit

Permalink
Expose ResolverMember on IObjectField (#3567)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Apr 22, 2021
1 parent 20ce7d9 commit 07e1f33
Show file tree
Hide file tree
Showing 24 changed files with 250 additions and 30 deletions.
23 changes: 23 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Contracts/IEnumType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,35 @@

namespace HotChocolate.Types
{
/// <summary>
/// Represents a GraphQL enum type
/// </summary>
public interface IEnumType : ILeafType
{
/// <summary>
/// The associated syntax node from the GraphQL SDL.
/// </summary>
new EnumTypeDefinitionNode? SyntaxNode { get; }

/// <summary>
/// Gets the possible enum values.
/// </summary>
IReadOnlyCollection<IEnumValue> Values { get; }

/// <summary>
/// Tries to get the <paramref name="runtimeValue"/> for
/// the specified <paramref name="name"/>.
/// </summary>
/// <param name="name">
/// The GraphQL enum value name.
/// </param>
/// <param name="runtimeValue">
/// The .NET runtime value.
/// </param>
/// <returns>
/// <c>true</c> if the <paramref name="name"/> represents a value of this enum type;
/// otherwise, <c>false</c>.
/// </returns>
bool TryGetRuntimeValue(
NameString name,
[NotNullWhen(true)]out object? runtimeValue);
Expand Down
17 changes: 17 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Contracts/IEnumType~1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@

namespace HotChocolate.Types
{
/// <summary>
/// Represents a GraphQL enum type
/// </summary>
public interface IEnumType<T> : IEnumType
{
/// <summary>
/// Tries to get the <paramref name="runtimeValue"/> for
/// the specified <paramref name="name"/>.
/// </summary>
/// <param name="name">
/// The GraphQL enum value name.
/// </param>
/// <param name="runtimeValue">
/// The .NET runtime value.
/// </param>
/// <returns>
/// <c>true</c> if the <paramref name="name"/> represents a value of this enum type;
/// otherwise, <c>false</c>.
/// </returns>
bool TryGetRuntimeValue(
NameString name,
[NotNullWhen(true)]out T runtimeValue);
Expand Down
15 changes: 15 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Contracts/IEnumValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,36 @@

namespace HotChocolate.Types
{
/// <summary>
/// Represents a GraphQL enum value.
/// </summary>
public interface IEnumValue
: IHasDirectives
, IHasReadOnlyContextData
{
/// <summary>
/// The associated syntax node from the GraphQL SDL.
/// </summary>
EnumValueDefinitionNode? SyntaxNode { get; }

/// <summary>
/// The GraphQL name of this enum value.
/// </summary>
NameString Name { get; }

/// <summary>
/// Gets the GraphQL description for this enum value.
/// </summary>
string? Description { get; }

/// <summary>
/// Defines if this enum value is deprecated.
/// </summary>
bool IsDeprecated { get; }

/// <summary>
/// Gets the deprecation reason for this enum value.
/// </summary>
string? DeprecationReason { get; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace HotChocolate.Types
{
/// <summary>
/// GraphQL type system members that have a description.
/// </summary>
public interface IHasDescription
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

namespace HotChocolate.Types
{
/// <summary>
/// GraphQL type system members that have directives.
/// </summary>
public interface IHasDirectives
{
/// <summary>
/// Gets the directives of this type system member.
/// </summary>
public IDirectiveCollection Directives { get; }
}
}
6 changes: 6 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Contracts/IHasName.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
namespace HotChocolate.Types
{
/// <summary>
/// GraphQL type system members that have a name.
/// </summary>
public interface IHasName
{
/// <summary>
/// Gets the GraphQL type system member name.
/// </summary>
NameString Name { get; }
}
}
3 changes: 3 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Contracts/IHasScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace HotChocolate.Types
{
/// <summary>
/// GraphQL type system members that can be scoped.
/// </summary>
public interface IHasScope
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace HotChocolate.Types
{
/// <summary>
/// GraphQL type system members that have a type identity.
/// </summary>
public interface IHasTypeIdentity
{
/// <summary>
/// Gets the type identity of this type system member.
/// </summary>
Type? TypeIdentity { get; }
}
}
3 changes: 3 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Contracts/ILeafType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace HotChocolate.Types
{
/// <summary>
/// Represents a GraphQL leaf-type e.g. scalar or enum.
/// </summary>
public interface ILeafType
: INamedOutputType
, INamedInputType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace HotChocolate.Types
{
/// <summary>
/// Represents a GraphQL input type which has a name.
/// </summary>
public interface INamedInputType
: INamedType
, IInputType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace HotChocolate.Types
{
/// <summary>
/// Represents a GraphQL output type which has a name.
/// </summary>
public interface INamedOutputType
: INamedType
, IOutputType
Expand Down
7 changes: 7 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Contracts/INamedType.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
namespace HotChocolate.Types
{
/// <summary>
/// Represents a named GraphQL type.
/// </summary>
public interface INamedType
: INullableType
, IHasName
, IHasDescription
, IHasSyntaxNode
, IHasReadOnlyContextData
{
/// <summary>
/// Determines whether an instance of a specified type <paramref name="type" />
/// can be assigned to a variable of the current type.
/// </summary>
bool IsAssignableFrom(INamedType type);
}
}
15 changes: 11 additions & 4 deletions src/HotChocolate/Core/src/Types/Types/Contracts/IObjectField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace HotChocolate.Types
/// <summary>
/// Represents a field of an <see cref="IObjectType"/>.
/// </summary>
public interface IObjectField
: IOutputField
public interface IObjectField : IOutputField
{
/// <summary>
/// Gets the type that declares this field.
Expand Down Expand Up @@ -38,9 +37,17 @@ public interface IObjectField
IReadOnlyList<IDirective> ExecutableDirectives { get; }

/// <summary>
/// Gets the associated .net type member of this field.
/// This member can be <c>null</c>.
/// Gets the associated member of the runtime type for this field.
/// This property can be <c>null</c> if this field is not associated to
/// a concrete member on the runtime type.
/// </summary>
MemberInfo? Member { get; }

/// <summary>
/// Gets the resolver member of this filed.
/// If this field has no explicit resolver member
/// this property will return <see cref="Member"/>.
/// </summary>
MemberInfo? ResolverMember { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
using HotChocolate.Language;

#nullable enable

namespace HotChocolate.Types
{
/// <summary>
/// Represents a GraphQL object type
/// </summary>
public interface IObjectType : IComplexOutputType
{
/// <summary>
/// The associated syntax node from the GraphQL SDL.
/// </summary>
new ObjectTypeDefinitionNode? SyntaxNode { get; }

/// <summary>
/// Gets the field that the type exposes.
/// </summary>
Expand Down
15 changes: 9 additions & 6 deletions src/HotChocolate/Core/src/Types/Types/Contracts/IUnionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace HotChocolate.Types
{
/// <summary>
/// Represents a GraphQL union type.
/// </summary>
public interface IUnionType : INamedOutputType
{
/// <summary>
Expand All @@ -19,7 +22,7 @@ public interface IUnionType : INamedOutputType
IReadOnlyCollection<IObjectType> Types { get; }

/// <summary>
/// Resolves the concrete type for the value of a type
/// Resolves the concrete type for the value of a type
/// that implements this interface.
/// </summary>
/// <param name="context">
Expand All @@ -29,35 +32,35 @@ public interface IUnionType : INamedOutputType
/// The value for which the type shall be resolved.
/// </param>
/// <returns>
/// Returns <c>null</c> if the value is not of a type
/// Returns <c>null</c> if the value is not of a type
/// implementing this interface.
/// </returns>
IObjectType? ResolveConcreteType(
IResolverContext context,
object resolverResult);

/// <summary>
/// Checks if the type set of this union type contains the
/// Checks if the type set of this union type contains the
/// specified <paramref name="objectType"/>.
/// </summary>
/// <param name="objectType">
/// The object type.
/// </param>
/// <returns>
/// Returns <c>true</c>, if the type set of this union type contains the
/// Returns <c>true</c>, if the type set of this union type contains the
/// specified <paramref name="objectType"/>; otherwise, <c>false</c> is returned.
/// </returns>
bool ContainsType(IObjectType objectType);

/// <summary>
/// Checks if the type set of this union type contains the
/// Checks if the type set of this union type contains the
/// specified <paramref name="typeName"/>.
/// </summary>
/// <param name="objectType">
/// The object type.
/// </param>
/// <returns>
/// Returns <c>true</c>, if the type set of this union type contains the
/// Returns <c>true</c>, if the type set of this union type contains the
/// specified <paramref name="typeName"/>; otherwise, <c>false</c> is returned.
/// </returns>
bool ContainsType(NameString typeName);
Expand Down
19 changes: 17 additions & 2 deletions src/HotChocolate/Core/src/Types/Types/ObjectField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ internal ObjectField(
: base(definition, fieldCoordinate, sortArgumentsByName)
{
Member = definition.Member;
ResolverMember = definition.ResolverMember ?? definition.Member;
Middleware = _empty;
Resolver = definition.Resolver!;
Expression = definition.Expression;
ResolverExpression = definition.Expression;
SubscribeResolver = definition.SubscribeResolver;
IsIntrospectionField = definition.IsIntrospectionField;
}
Expand Down Expand Up @@ -69,11 +70,25 @@ internal ObjectField(
/// </summary>
public MemberInfo? Member { get; }

/// <summary>
/// Gets the resolver member of this filed.
/// If this field has no explicit resolver member
/// this property will return <see cref="Member"/>.
/// </summary>
public MemberInfo? ResolverMember { get; }

/// <summary>
/// Gets the associated resolver expression.
/// This expression can be <c>null</c>.
/// </summary>
[Obsolete("Use resolver expression.")]
public Expression? Expression => ResolverExpression;

/// <summary>
/// Gets the associated resolver expression.
/// This expression can be <c>null</c>.
/// </summary>
public Expression? Expression { get; }
public Expression? ResolverExpression { get; }

/// <summary>
/// Defines if this field as a introspection field.
Expand Down
16 changes: 16 additions & 0 deletions src/HotChocolate/Core/test/Types.Tests/NamingConventionTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using HotChocolate.Execution;
using HotChocolate.Tests;
using HotChocolate.Types;
using HotChocolate.Types.Descriptors;
using Microsoft.Extensions.DependencyInjection;
using Snapshooter.Xunit;
using Xunit;

Expand All @@ -21,6 +25,18 @@ public void PureCodeFirst_NamingConvention_RenameArgument()
.MatchSnapshot();
}

[Fact]
public async Task PureCodeFirst_NamingConvention_RenameArgument_RequestBuilder()
{
await new ServiceCollection()
.AddGraphQL()
.AddQueryType<QueryNamingConvention>()
.AddMutationType<MutationNamingConvention>()
.AddConvention<INamingConventions, CustomNamingConvention>()
.BuildSchemaAsync()
.MatchSnapshotAsync();
}

public class CustomNamingConvention : DefaultNamingConventions
{
public override NameString GetArgumentName(ParameterInfo parameter)
Expand Down
Loading

0 comments on commit 07e1f33

Please sign in to comment.