private static IObjectFieldDescriptor UseFiltering(
            IObjectFieldDescriptor descriptor,
            Type filterType)
        {
            FieldMiddleware placeholder =
                next => context => Task.CompletedTask;

            descriptor
            .Use(placeholder)
            .Extend()
            .OnBeforeCreate(definition =>
            {
                Type argumentType = filterType;

                if (filterType == null)
                {
                    if (!TypeInspector.Default.TryCreate(
                            definition.ResultType, out TypeInfo typeInfo))
                    {
                        // TODO : resources
                        throw new ArgumentException(
                            "Cannot handle the specified type.",
                            nameof(descriptor));
                    }

                    argumentType =
                        typeof(FilterInputType <>).MakeGenericType(
                            typeInfo.ClrType);
                }

                var argumentTypeReference = new ClrTypeReference(
                    argumentType,
                    TypeContext.Input);

                if (argumentType == typeof(object))
                {
                    // TODO : resources
                    throw new SchemaException(
                        SchemaErrorBuilder.New()
                        .SetMessage(
                            "The filter type cannot be " +
                            "infered from `System.Object`.")
                        .SetCode("FILTER_OBJECT_TYPE")
                        .Build());
                }

                var argumentDefinition  = new ArgumentDefinition();
                argumentDefinition.Name = _whereArgumentName;
                argumentDefinition.Type = new ClrTypeReference(
                    argumentType, TypeContext.Input);
                definition.Arguments.Add(argumentDefinition);

                ILazyTypeConfiguration lazyConfiguration =
                    LazyTypeConfigurationBuilder
                    .New <ObjectFieldDefinition>()
                    .Definition(definition)
                    .Configure((context, defintion) =>
                               CompileMiddleware(
                                   context,
                                   definition,
                                   argumentTypeReference,
                                   placeholder))
                    .On(ApplyConfigurationOn.Completion)
                    .DependsOn(argumentTypeReference, true)
                    .Build();
                definition.Configurations.Add(lazyConfiguration);
            });

            return(descriptor);
        }
Esempio n. 2
0
 public Variable(ClrVariableName Name, ClrTypeReference typeref = null, CodeDocumentationSpec Documentation = null)
     : base(Name, Documentation, ClrAccessKind.Default, array <AttributionSpec>())
 {
     this.VariableType = typeref;
 }
Esempio n. 3
0
 public ClrMemberReference(ClrTypeReference DeclaringType, ClrItemIdentifier MemberName)
 {
     this.DeclaringType = DeclaringType;
     this.MemberName    = MemberName;
 }
Esempio n. 4
0
 public EnumSpec(ClrEnumName Name, ClrTypeReference UnderlyingType,
                 params (string literalName, object literalValue)[] literals)
Esempio n. 5
0
 /// <summary>
 /// Defines a consructor invocation
 /// </summary>
 /// <param name="type">The type that defines the constructor</param>
 /// <param name="arguments">The arguments to supply upon invocation</param>
 /// <returns></returns>
 public static ConstructorInvocationSpec CreateObject(this ClrTypeReference type, params MethodArgumentValueSpec[] arguments)
 => new ConstructorInvocationSpec(type, arguments);
Esempio n. 6
0
 public ConstructorInvocationSpec(ClrTypeReference TypeReference, params MethodArgumentValueSpec[] Arguments)
 {
     this.TypeReference = TypeReference;
     this.Arguments     = rolist(Arguments);
 }