protected FilterFieldDescriptor( IDescriptorContext context, string?scope, MemberInfo member) : base(context) { IFilterConvention convention = context.GetFilterConvention(scope); Definition.Member = member ?? throw new ArgumentNullException(nameof(member)); Definition.Name = convention.GetFieldName(member); Definition.Description = convention.GetFieldDescription(member); Definition.Type = convention.GetFieldType(member); Definition.Scope = scope; }
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); }