public static IObjectFieldDescriptor UsePaging <TSchemaType>(
            this IObjectFieldDescriptor descriptor)
            where TSchemaType : IOutputType, new()
        {
            FieldMiddleware placeholder =
                next => context => Task.CompletedTask;
            Type middlewareDefinition = typeof(QueryableConnectionMiddleware <>);

            descriptor
            .AddPagingArguments()
            .Type(ConnectionType <TSchemaType> .CreateWithTotalCount())
            .Use(placeholder)
            .Extend()
            .OnBeforeCompletion((context, defintion) =>
            {
                var reference = new ClrTypeReference(
                    typeof(TSchemaType),
                    TypeContext.Output);
                IOutputType type = context.GetType <IOutputType>(reference);
                if (type.NamedType() is IHasClrType hasClrType)
                {
                    Type middlewareType = middlewareDefinition
                                          .MakeGenericType(hasClrType.ClrType);
                    FieldMiddleware middleware =
                        FieldClassMiddlewareFactory.Create(middlewareType);
                    int index =
                        defintion.MiddlewareComponents.IndexOf(placeholder);
                    defintion.MiddlewareComponents[index] = middleware;
                }
            })
            .DependsOn <TSchemaType>();

            return(descriptor);
        }
示例#2
0
        public static IObjectFieldDescriptor UsePaging <TSchemaType>(
            this IObjectFieldDescriptor descriptor)
            where TSchemaType : class, IOutputType
        {
            FieldMiddleware placeholder          = next => context => default(ValueTask);
            Type            middlewareDefinition = typeof(QueryableConnectionMiddleware <>);

            descriptor
            .AddPagingArguments()
            .Type <ConnectionWithCountType <TSchemaType> >()
            .Use(placeholder)
            .Extend()
            .OnBeforeCompletion((context, defintion) =>
            {
                ITypeReference reference =
                    context.DescriptorContext.TypeInspector.GetTypeRef(typeof(TSchemaType));
                IOutputType type = context.GetType <IOutputType>(reference);
                if (type.NamedType() is IHasRuntimeType hasClrType)
                {
                    Type middlewareType = middlewareDefinition.MakeGenericType(
                        hasClrType.RuntimeType);
                    FieldMiddleware middleware = FieldClassMiddlewareFactory.Create(
                        middlewareType);
                    int index = defintion.MiddlewareComponents.IndexOf(placeholder);
                    defintion.MiddlewareComponents[index] = middleware;
                }
            })
            .DependsOn <TSchemaType>();

            return(descriptor);
        }
        public static IObjectFieldDescriptor UsePaging(
            this IObjectFieldDescriptor descriptor,
            Type?type       = null,
            Type?entityType = null,
            GetCursorPagingProvider?resolvePagingProvider = null,
            PagingOptions options = default)
        {
            if (descriptor is null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            resolvePagingProvider ??= ResolvePagingProvider;

            descriptor.AddPagingArguments();

            PagingHelper.UsePaging(
                descriptor,
                type,
                entityType,
                (services, source) => resolvePagingProvider(services, source),
                options);

            descriptor
            .Extend()
            .OnBeforeCreate(
                (c, d) => d.Type = CreateConnectionTypeRef(
                    c, d.ResolverMember ?? d.Member, type, options));

            return(descriptor);
        }
 public static IObjectFieldDescriptor UsePaging <TSchemaType, TClrType>(
     this IObjectFieldDescriptor descriptor)
     where TSchemaType : INamedOutputType, new()
 {
     return(descriptor
            .AddPagingArguments()
            .Type <ConnectionType <TSchemaType> >()
            .Use <QueryableConnectionMiddleware <TClrType> >());
 }
示例#5
0
 public static IObjectFieldDescriptor UsePaging <TSchemaType, TClrType>(
     this IObjectFieldDescriptor descriptor)
     where TSchemaType : class, IOutputType
 {
     return(descriptor
            .AddPagingArguments()
            .Type(ConnectionType <TSchemaType> .CreateWithTotalCount())
            .Use <QueryableConnectionMiddleware <TClrType> >());
 }
示例#6
0
        public static IObjectFieldDescriptor UsePaging <TSchemaType>(
            this IObjectFieldDescriptor descriptor)
            where TSchemaType : IOutputType, new()
        {
            descriptor
            .AddPagingArguments()
            .Type(ConnectionType <TSchemaType> .CreateWithTotalCount());

            if (NamedTypeInfoFactory.Default.TryExtractClrType(
                    typeof(TSchemaType), out Type clrType))
            {
                Type middlewareType = typeof(QueryableConnectionMiddleware <>)
                                      .MakeGenericType(clrType);
                _use.MakeGenericMethod(middlewareType)
                .Invoke(null, new object[] { descriptor });
            }

            return(descriptor);
        }