Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Feb 12, 2024
1 parent 9f3e5b0 commit 173dc86
Show file tree
Hide file tree
Showing 70 changed files with 244 additions and 536 deletions.
4 changes: 0 additions & 4 deletions src/HotChocolate/Caching/src/Caching/ErrorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static ISchemaError CacheControlInheritMaxAgeOnQueryTypeField(
field.Coordinate.ToString(),
type.Name)
.SetTypeSystemObject(type)
.AddSyntaxNode(field.SyntaxNode)
.Build();

public static ISchemaError CacheControlOnInterfaceField(
Expand All @@ -33,7 +32,6 @@ public static ISchemaError CacheControlOnInterfaceField(
ErrorHelper_CacheControlOnInterfaceField,
field.Coordinate.ToString())
.SetTypeSystemObject(type)
.AddSyntaxNode(field.SyntaxNode)
.Build();

public static ISchemaError CacheControlNegativeMaxAge(
Expand All @@ -44,7 +42,6 @@ public static ISchemaError CacheControlNegativeMaxAge(
ErrorHelper_CacheControlNegativeMaxAge,
field.Coordinate.ToString())
.SetTypeSystemObject(type)
.AddSyntaxNode(field.SyntaxNode)
.Build();

public static ISchemaError CacheControlBothMaxAgeAndInheritMaxAge(
Expand All @@ -55,6 +52,5 @@ public static ISchemaError CacheControlBothMaxAgeAndInheritMaxAge(
ErrorHelper_CacheControlBothMaxAgeAndInheritMaxAge,
field.Coordinate.ToString())
.SetTypeSystemObject(type)
.AddSyntaxNode(field.SyntaxNode)
.Build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static GraphQLException PagingHandler_MaxPageSize(
.SetMessage(ThrowHelper_PagingHandler_MaxPageSize)
.SetCode(ErrorCodes.Paging.MaxPaginationItems)
.SetPath(path)
.SetSyntaxNode(field.SyntaxNode)
.SetExtension(nameof(field), field.Coordinate.ToString())
.SetExtension(nameof(requestedItems), requestedItems)
.SetExtension(nameof(maxAllowedItems), maxAllowedItems)
Expand All @@ -32,7 +31,6 @@ public static GraphQLException PagingHandler_NoBoundariesSet(
field.Type.TypeName())
.SetCode(ErrorCodes.Paging.NoPagingBoundaries)
.SetPath(path)
.SetSyntaxNode(field.SyntaxNode)
.SetExtension(nameof(field), field.Coordinate.ToString())
.Build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public static GraphQLException OffsetPagingHandler_MaxPageSize(
.SetMessage("The maximum allowed items per page were exceeded.")
.SetCode(ErrorCodes.Paging.MaxPaginationItems)
.SetPath(path)
.SetSyntaxNode(field.SyntaxNode)
.SetExtension(nameof(field), field.Coordinate.ToString())
.SetExtension(nameof(requestedItems), requestedItems)
.SetExtension(nameof(maxAllowedItems), maxAllowedItems)
Expand All @@ -30,7 +29,6 @@ public static GraphQLException OffsetPagingHandler_NoBoundariesSet(
field.Type.NamedType().Name)
.SetCode(ErrorCodes.Paging.NoPagingBoundaries)
.SetPath(path)
.SetSyntaxNode(field.SyntaxNode)
.SetExtension(nameof(field), field.Coordinate.ToString())
.Build());
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ private static void EnsureOneOfFieldsAreValid(
}

temp.Clear();
errors.Add(OneofInputObjectMustHaveNullableFieldsWithoutDefaults(type, fieldNames));
errors.Add(OneOfInputObjectMustHaveNullableFieldsWithoutDefaults(type, fieldNames));
}
}
5 changes: 0 additions & 5 deletions src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public interface IReadOnlySchemaOptions
/// </summary>
bool SortFieldsByName { get; }

/// <summary>
/// Defines if syntax nodes shall be preserved on the type system objects
/// </summary>
bool PreserveSyntaxNodes { get; }

/// <summary>
/// Defines if types shall be removed from the schema that are
/// unreachable from the root types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using HotChocolate.Subscriptions;
using HotChocolate.Types.Descriptors;
using HotChocolate.Utilities;
using Microsoft.Extensions.DependencyInjection;
using static System.Linq.Expressions.Expression;
using static HotChocolate.Properties.TypeResources;
using static HotChocolate.Resolvers.ResolveResultHelper;
Expand Down Expand Up @@ -48,8 +49,12 @@ internal sealed class DefaultResolverCompiler : IResolverCompiler
new Dictionary<ParameterInfo, string>();

public DefaultResolverCompiler(
IServiceProvider schemaServiceProvider,
IEnumerable<IParameterExpressionBuilder>? customParameterExpressionBuilders)
{
var appServiceProvider = schemaServiceProvider.GetService<IApplicationServiceProvider>();
var serviceInspector = appServiceProvider?.GetService<IServiceProviderIsService>();

var custom = customParameterExpressionBuilders is not null
? [..customParameterExpressionBuilders,]
: new List<IParameterExpressionBuilder>();
Expand Down Expand Up @@ -98,6 +103,11 @@ public DefaultResolverCompiler(
expressionBuilders.Add(new CustomServiceParameterExpressionBuilder<ITopicEventReceiver>());
expressionBuilders.Add(new CustomServiceParameterExpressionBuilder<ITopicEventSender>());

if (serviceInspector is not null)
{
expressionBuilders.Add(new InferredServiceParameterExpressionBuilder(serviceInspector));
}

if (customParameterExpressionBuilders is not null)
{
var defaultParameterExpressionBuilders = new List<IParameterExpressionBuilder>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#nullable enable

using System.Linq.Expressions;
using System.Reflection;
using HotChocolate.Internal;
using Microsoft.Extensions.DependencyInjection;

namespace HotChocolate.Resolvers.Expressions.Parameters;

/// <summary>
/// Builds parameter expressions for resolver level dependency injection for inferred services.
/// </summary>
internal sealed class InferredServiceParameterExpressionBuilder(IServiceProviderIsService serviceInspector)
: IParameterExpressionBuilder
{
public ArgumentKind Kind => ArgumentKind.Service;

public bool IsPure => true;

public bool IsDefaultHandler => false;

public bool CanHandle(ParameterInfo parameter)
=> serviceInspector.IsService(parameter.ParameterType);

public Expression Build(ParameterExpressionBuilderContext context)
{
#if NET8_0_OR_GREATER
return ServiceExpressionHelper.TryGetServiceKey(context.Parameter, out var key)
? ServiceExpressionHelper.Build(
context.Parameter,
context.ResolverContext,
ServiceKind.Default,
key)
: ServiceExpressionHelper.Build(
context.Parameter,
context.ResolverContext,
ServiceKind.Default);
#else
return ServiceExpressionHelper.Build(
context.Parameter,
context.ResolverContext,
ServiceKind.Default);
#endif
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq.Expressions;
using System.Reflection;
using HotChocolate.Internal;
Expand Down Expand Up @@ -44,4 +45,4 @@ public Expression Build(ParameterExpressionBuilderContext context)
ServiceKind.Default);
#endif
}
}
}
13 changes: 1 addition & 12 deletions src/HotChocolate/Core/src/Types/SchemaOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ public class SchemaOptions : IReadOnlySchemaOptions
{
private BindingBehavior _defaultBindingBehavior = BindingBehavior.Implicit;
private FieldBindingFlags _defaultFieldBindingFlags = FieldBindingFlags.Instance;
private string? _queryTypeName;

/// <summary>
/// Gets or sets the name of the query type.
/// </summary>
public string? QueryTypeName
{
get => _queryTypeName;
set => _queryTypeName = value;
}
public string? QueryTypeName { get; set; }

/// <summary>
/// Gets or sets the name of the mutation type.
Expand Down Expand Up @@ -58,11 +53,6 @@ public string? QueryTypeName
/// </summary>
public bool SortFieldsByName { get; set; }

/// <summary>
/// Defines if syntax nodes shall be preserved on the type system objects
/// </summary>
public bool PreserveSyntaxNodes { get; set; }

/// <summary>
/// Defines if types shall be removed from the schema that are
/// unreachable from the root types.
Expand Down Expand Up @@ -243,7 +233,6 @@ public static SchemaOptions FromOptions(IReadOnlySchemaOptions options)
ResolveXmlDocumentationFileName = options.ResolveXmlDocumentationFileName,
FieldMiddleware = options.FieldMiddleware,
DefaultBindingBehavior = options.DefaultBindingBehavior,
PreserveSyntaxNodes = options.PreserveSyntaxNodes,
EnableDirectiveIntrospection = options.EnableDirectiveIntrospection,
DefaultDirectiveVisibility = options.DefaultDirectiveVisibility,
DefaultResolverStrategy = options.DefaultResolverStrategy,
Expand Down
5 changes: 0 additions & 5 deletions src/HotChocolate/Core/src/Types/Types/Contracts/IEnumValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ public interface IEnumValue
, IHasReadOnlyContextData
, ITypeSystemMember
{
/// <summary>
/// The associated syntax node from the GraphQL SDL.
/// </summary>
EnumValueDefinitionNode? SyntaxNode { get; }

/// <summary>
/// The GraphQL name of this enum value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ protected override void OnCreateDefinition(ArgumentDefinition definition)
base.OnCreateDefinition(definition);
}

/// <inheritdoc />
public new IArgumentDescriptor SyntaxNode(InputValueDefinitionNode inputValueDefinition)
{
base.SyntaxNode(inputValueDefinition);
return this;
}

/// <inheritdoc />
public new IArgumentDescriptor Deprecated(string reason)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ public interface IArgumentDescriptor
: IDescriptor<ArgumentDefinition>
, IFluent
{
/// <summary>
/// Associates the argument with a syntax node of the parsed GraphQL SDL.
/// </summary>
/// <param name="inputValueDefinition">The syntax node</param>
IArgumentDescriptor SyntaxNode(InputValueDefinitionNode inputValueDefinition);

/// <summary>
/// Marks the argument as deprecated
/// <remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ public interface IDirectiveArgumentDescriptor
: IDescriptor<DirectiveArgumentDefinition>
, IFluent
{
/// <inheritdoc cref="IArgumentDescriptor.SyntaxNode(InputValueDefinitionNode)"/>
IDirectiveArgumentDescriptor SyntaxNode(InputValueDefinitionNode inputValueDefinition);

/// <inheritdoc cref="IArgumentDescriptor.Deprecated(string)"/>
IDirectiveArgumentDescriptor Deprecated(string reason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ public interface IDirectiveTypeDescriptor<T>
: IDescriptor<DirectiveTypeDefinition>
, IFluent
{
/// <summary>
/// Associates the specified <paramref name="directiveDefinitionNode"/>
/// with the <see cref="DirectiveType"/>.
/// </summary>
/// <param name="directiveDefinitionNode">
/// The <see cref="DirectiveDefinitionNode"/> of a parsed schema.
/// </param>
IDirectiveTypeDescriptor<T> SyntaxNode(
DirectiveDefinitionNode directiveDefinitionNode);

/// <summary>
/// Defines the name of the <see cref="DirectiveType"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ public interface IEnumTypeDescriptor
: IDescriptor<EnumTypeDefinition>
, IFluent
{
/// <summary>
/// Associates the enum type with a syntax node
/// of the parsed GraphQL SDL.
/// </summary>
/// <param name="enumTypeDefinition">
/// The the type definition node.
/// </param>
IEnumTypeDescriptor SyntaxNode(
EnumTypeDefinitionNode enumTypeDefinition);

/// <summary>
/// Defines the name the enum type shall have.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ public interface IEnumTypeDescriptor<TRuntimeType>
: IDescriptor<EnumTypeDefinition>
, IFluent
{
/// <summary>
/// Associates the enum type with a syntax node
/// of the parsed GraphQL SDL.
/// </summary>
/// <param name="enumTypeDefinition">
/// The the type definition node.
/// </param>
IEnumTypeDescriptor<TRuntimeType> SyntaxNode(
EnumTypeDefinitionNode enumTypeDefinition);

/// <summary>
/// Defines the name the enum type shall have.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ public interface IInputFieldDescriptor
: IDescriptor<InputFieldDefinition>
, IFluent
{
/// <summary>
/// Associates the argument with a syntax node of the parsed GraphQL SDL.
/// </summary>
/// <param name="inputValueDefinition">The syntax node</param>
IInputFieldDescriptor SyntaxNode(InputValueDefinitionNode inputValueDefinition);

/// <summary>
/// Sets the name of the argument
/// <example>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ public interface IInputObjectTypeDescriptor
: IDescriptor<InputObjectTypeDefinition>
, IFluent
{
IInputObjectTypeDescriptor SyntaxNode(
InputObjectTypeDefinitionNode inputObjectTypeDefinition);

IInputObjectTypeDescriptor Name(string value);

IInputObjectTypeDescriptor Description(string value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public interface IInputObjectTypeDescriptor<T>
: IDescriptor<InputObjectTypeDefinition>
, IFluent
{
IInputObjectTypeDescriptor<T> SyntaxNode(
InputObjectTypeDefinitionNode inputObjectTypeDefinition);

IInputObjectTypeDescriptor<T> Name(string value);

IInputObjectTypeDescriptor<T> Description(string value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ public interface IInterfaceFieldDescriptor
: IDescriptor<InterfaceFieldDefinition>
, IFluent
{
IInterfaceFieldDescriptor SyntaxNode(
FieldDefinitionNode fieldDefinition);

IInterfaceFieldDescriptor Name(string value);

IInterfaceFieldDescriptor Description(string value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ public interface IInterfaceTypeDescriptor
: IDescriptor<InterfaceTypeDefinition>
, IFluent
{
/// <summary>
/// Associates the specified
/// <paramref name="interfaceTypeDefinition"/>
/// with the <see cref="InterfaceType"/>.
/// </summary>
/// <param name="interfaceTypeDefinition">
/// The <see cref="InterfaceTypeDefinitionNode"/> of a parsed schema.
/// </param>
IInterfaceTypeDescriptor SyntaxNode(
InterfaceTypeDefinitionNode interfaceTypeDefinition);

/// <summary>
/// Defines the name of the <see cref="InterfaceType"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ public interface IInterfaceTypeDescriptor<T>
: IDescriptor<InterfaceTypeDefinition>
, IFluent
{
/// <summary>
/// Associates the specified
/// <paramref name="interfaceTypeDefinition"/>
/// with the <see cref="InterfaceType"/>.
/// </summary>
/// <param name="interfaceTypeDefinition">
/// The <see cref="InterfaceTypeDefinitionNode"/> of a parsed schema.
/// </param>
IInterfaceTypeDescriptor<T> SyntaxNode(
InterfaceTypeDefinitionNode interfaceTypeDefinition);

/// <summary>
/// Defines the name of the <see cref="InterfaceType"/>.
/// </summary>
Expand Down
Loading

0 comments on commit 173dc86

Please sign in to comment.