public static IObjectFieldDescriptor UseSorting( this IObjectFieldDescriptor descriptor, Type?sortType, ITypeSystemMember?sortTypeInstance = null) { FieldMiddlewareDefinition placeholder = new(_ => _ => default, key : WellKnownMiddleware.Sorting);
private static IObjectFieldDescriptor UseFiltering( IObjectFieldDescriptor descriptor, Type?filterType, ITypeSystemMember?filterTypeInstance = null) { FieldMiddlewareDefinition placeholder = new(_ => _ => default, key : WellKnownMiddleware.Filtering);
private static IObjectFieldDescriptor UseFiltering( IObjectFieldDescriptor descriptor, Type?filterType, ITypeSystemMember?filterTypeInstance, string?scope) { FieldMiddlewareDefinition placeholder = new(_ => _ => default);
private static IObjectFieldDescriptor UseFiltering( IObjectFieldDescriptor descriptor, Type?filterType, ITypeSystemMember?filterTypeInstance, string?scope) { FieldMiddleware placeholder = next => context => default; string argumentPlaceholder = "_" + Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); descriptor .Use(placeholder) .Extend() .OnBeforeCreate( (c, definition) => { IFilterConvention convention = c.GetFilterConvention(scope); ITypeReference argumentTypeReference; if (filterTypeInstance is not null) { argumentTypeReference = TypeReference.Create(filterTypeInstance, scope); } else if (filterType is null) { if (definition.ResultType is null || definition.ResultType == typeof(object) || !c.TypeInspector.TryCreateTypeInfo( definition.ResultType, out ITypeInfo? typeInfo)) { throw new ArgumentException( FilterObjectFieldDescriptorExtensions_UseFiltering_CannotHandleType, nameof(descriptor)); } argumentTypeReference = convention.GetFieldType(typeInfo.NamedType); } else { argumentTypeReference = c.TypeInspector.GetTypeRef( filterType, TypeContext.Input, scope); } var argumentDefinition = new ArgumentDefinition { Name = argumentPlaceholder, Type = argumentTypeReference }; definition.Arguments.Add(argumentDefinition); definition.Configurations.Add( LazyTypeConfigurationBuilder .New <ObjectFieldDefinition>() .Definition(definition) .Configure( (context, definition) => CompileMiddleware( context, definition, argumentTypeReference, placeholder, scope)) .On(ApplyConfigurationOn.Completion) .DependsOn(argumentTypeReference, true) .Build()); argumentDefinition.Configurations.Add( LazyTypeConfigurationBuilder .New <ArgumentDefinition>() .Definition(argumentDefinition) .Configure( (context, argumentDefinition) => argumentDefinition.Name = context.GetFilterConvention(scope).GetArgumentName()) .On(ApplyConfigurationOn.Naming) .Build()); }); return(descriptor); }
public static IObjectFieldDescriptor UseSorting( this IObjectFieldDescriptor descriptor, Type?sortType, ITypeSystemMember?sortTypeInstance = null) { FieldMiddleware placeholder = next => context => default; string argumentPlaceholder = "_" + Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); descriptor .Use(placeholder) .Extend() .OnBeforeCreate((c, definition) => { Type argumentType = GetArgumentType(definition, sortType, c.TypeInspector); ITypeReference argumentTypeReference = sortTypeInstance is null ? (ITypeReference)c.TypeInspector.GetTypeRef( argumentType, TypeContext.Input) : TypeReference.Create(sortTypeInstance); var argumentDefinition = new ArgumentDefinition { Name = argumentPlaceholder, Type = c.TypeInspector.GetTypeRef(argumentType, TypeContext.Input) }; ILazyTypeConfiguration lazyArgumentConfiguration = LazyTypeConfigurationBuilder .New <ArgumentDefinition>() .Definition(argumentDefinition) .Configure((context, definition) => { ISortingNamingConvention convention = context.DescriptorContext.GetSortingNamingConvention(); definition.Name = convention.ArgumentName; }) .On(ApplyConfigurationOn.Completion) .Build(); argumentDefinition.Configurations.Add(lazyArgumentConfiguration); definition.Arguments.Add(argumentDefinition); ILazyTypeConfiguration lazyConfiguration = LazyTypeConfigurationBuilder .New <ObjectFieldDefinition>() .Definition(definition) .Configure((context, definition) => CompileMiddleware( context, definition, argumentTypeReference, placeholder)) .On(ApplyConfigurationOn.Completion) .DependsOn(argumentTypeReference, true) .Build(); definition.Configurations.Add(lazyConfiguration); }); return(descriptor); }
private static IObjectFieldDescriptor UseSorting( IObjectFieldDescriptor descriptor, Type?sortType, ITypeSystemMember?sortTypeInstance, string?scope) { FieldMiddleware placeholder = next => context => default; string argumentPlaceholder = "_" + Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); descriptor .Use(placeholder) .Extend() .OnBeforeCreate( (c, definition) => { Type?argumentType = sortType; if (argumentType is null) { if (definition.ResultType is null || definition.ResultType == typeof(object) || !c.TypeInspector.TryCreateTypeInfo( definition.ResultType, out ITypeInfo? typeInfo)) { throw new ArgumentException( SortObjectFieldDescriptorExtensions_UseSorting_CannotHandleType, nameof(descriptor)); } argumentType = typeof(SortInputType <>) .MakeGenericType(typeInfo.NamedType); } ITypeReference argumentTypeReference = sortTypeInstance is null ? (ITypeReference)c.TypeInspector.GetTypeRef( argumentType, TypeContext.Input, scope) : TypeReference.Create(sortTypeInstance, scope); if (argumentType == typeof(object)) { throw SortObjectFieldDescriptorExtensions_CannotInfer(); } argumentType = typeof(ListType <>).MakeGenericType(argumentType); var argumentDefinition = new ArgumentDefinition { Name = argumentPlaceholder, Type = c.TypeInspector.GetTypeRef( argumentType, TypeContext.Input, scope) }; definition.Arguments.Add(argumentDefinition); definition.Configurations.Add( LazyTypeConfigurationBuilder .New <ObjectFieldDefinition>() .Definition(definition) .Configure( (context, def) => CompileMiddleware( context, def, argumentTypeReference, placeholder, scope)) .On(ApplyConfigurationOn.Completion) .DependsOn(argumentTypeReference, true) .Build()); definition.Configurations.Add( LazyTypeConfigurationBuilder .New <ObjectFieldDefinition>() .Definition(definition) .Configure( (context, _) => argumentDefinition.Name = context.GetSortConvention(scope).GetArgumentName()) .On(ApplyConfigurationOn.Naming) .Build()); }); return(descriptor); }
private static IObjectFieldDescriptor UseFiltering( IObjectFieldDescriptor descriptor, Type?filterType, ITypeSystemMember?filterTypeInstance = null) { FieldMiddleware placeholder = next => context => Task.CompletedTask; descriptor .Use(placeholder) .Extend() .OnBeforeCreate(definition => { Type?argumentType = filterType; if (argumentType == null) { if (!TypeInspector.Default.TryCreate( definition.ResultType, out TypeInfo typeInfo)) { throw new ArgumentException( FilterResources.FilterObjectFieldDescriptor_InvalidType, nameof(descriptor)); } argumentType = typeof(FilterInputType <>).MakeGenericType(typeInfo.ClrType); } ITypeReference argumentTypeReference = filterTypeInstance is null ? (ITypeReference) new ClrTypeReference(argumentType, TypeContext.Input) : new SchemaTypeReference(filterTypeInstance); if (argumentType == typeof(object)) { throw new SchemaException( SchemaErrorBuilder.New() .SetMessage( FilterResources.FilterObjectFieldDescriptor_InvalidType_Msg) .SetCode(ErrorCodes.Filtering.FilterObjectType) .Build()); } var argumentDefinition = new ArgumentDefinition { Type = new ClrTypeReference(argumentType, TypeContext.Input) }; argumentDefinition.ConfigureArgumentName(); definition.Arguments.Add(argumentDefinition); ILazyTypeConfiguration lazyConfiguration = LazyTypeConfigurationBuilder .New <ObjectFieldDefinition>() .Definition(definition) .Configure((context, definition) => CompileMiddleware( context, definition, argumentTypeReference, placeholder)) .On(ApplyConfigurationOn.Completion) .DependsOn(argumentTypeReference, true) .Build(); definition.Configurations.Add(lazyConfiguration); }); return(descriptor); }
public static IObjectFieldDescriptor UseSorting( this IObjectFieldDescriptor descriptor, Type?sortType, ITypeSystemMember?sortTypeInstance = null) { FieldMiddleware placeholder = next => context => Task.CompletedTask; descriptor .Use(placeholder) .Extend() .OnBeforeCreate(definition => { Type argumentType = GetArgumentType(definition, sortType); ITypeReference argumentTypeReference = sortTypeInstance is null ? (ITypeReference) new ClrTypeReference( argumentType, TypeContext.Input) : new SchemaTypeReference(sortTypeInstance); var argumentDefinition = new ArgumentDefinition { Type = new ClrTypeReference( argumentType, TypeContext.Input) }; ILazyTypeConfiguration lazyArgumentConfiguration = LazyTypeConfigurationBuilder .New <ArgumentDefinition>() .Definition(argumentDefinition) .Configure((context, definition) => { ISortingNamingConvention convention = context.DescriptorContext.GetSortingNamingConvention(); definition.Name = convention.ArgumentName; }) .On(ApplyConfigurationOn.Completion) .Build(); argumentDefinition.Configurations.Add(lazyArgumentConfiguration); definition.Arguments.Add(argumentDefinition); ILazyTypeConfiguration lazyConfiguration = LazyTypeConfigurationBuilder .New <ObjectFieldDefinition>() .Definition(definition) .Configure((context, definition) => CompileMiddleware( context, definition, argumentTypeReference, placeholder)) .On(ApplyConfigurationOn.Completion) .DependsOn(argumentTypeReference, true) .Build(); definition.Configurations.Add(lazyConfiguration); }); return(descriptor); }