public static IObjectFieldDescriptor UsePagination <TSchemaType, TClrType>(this IObjectFieldDescriptor descriptor) where TSchemaType : class, IOutputType { return(descriptor .AddPaginationArguments() .Type <PaginationType <TSchemaType> >() .Use <QueryableConnectionMiddleware <TClrType> >()); }
public static IObjectFieldDescriptor UsePagination <TSchemaType>(this IObjectFieldDescriptor descriptor) where TSchemaType : class, IOutputType { FieldMiddleware placeholder = next => default(FieldDelegate); Type middlewareDefinition = typeof(QueryableConnectionMiddleware <>); descriptor .AddPaginationArguments() .Type <PaginationType <TSchemaType> >() .Use(placeholder) .Extend() .OnBeforeCompletion((context, defintion) => { var reference = typeof(TSchemaType)?.BaseType?.GenericTypeArguments?[0]; if (reference != null) { Type middlewareType = middlewareDefinition.MakeGenericType(reference); FieldMiddleware middleware = FieldClassMiddlewareFactory.Create( middlewareType); int index = defintion.MiddlewareComponents.IndexOf(placeholder); defintion.MiddlewareComponents[index] = middleware; } }) .DependsOn <TSchemaType>(); return(descriptor); }