public static IObjectFieldDescriptor Resolver <TResult>( this IObjectFieldDescriptor descriptor, Func <IResolverContext, TResult> fieldResolver) { return(descriptor .Type <NativeType <TResult> >() .Resolver(ctx => Task.FromResult <object>(fieldResolver(ctx)), typeof(NativeType <TResult>))); }
/// <summary> /// Specifies the type of an object field with GraphQL SDL type syntax. /// </summary> /// <param name="descriptor"> /// The object field descriptor. /// </param> /// <param name="typeSyntax"> /// The GraphQL SDL type syntax. /// </param> /// <returns> /// Returns the object field descriptor for configuration chaining. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="descriptor"/> is <c>null</c>. /// <paramref name="typeSyntax"/> is <c>null</c>. /// </exception> /// <exception cref="SyntaxException"> /// The GraphQL SDL type syntax is invalid. /// </exception> public static IObjectFieldDescriptor Type( this IObjectFieldDescriptor descriptor, string typeSyntax) { if (descriptor is null) { throw new ArgumentNullException(nameof(descriptor)); } if (typeSyntax is null) { throw new ArgumentNullException(nameof(typeSyntax)); } return(descriptor.Type(Utf8GraphQLParser.Syntax.ParseTypeReference(typeSyntax))); }
public static IObjectFieldDescriptor Resolver <TResult>( this IObjectFieldDescriptor descriptor, Func <IResolverContext, TResult> resolver) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (resolver == null) { throw new ArgumentNullException(nameof(resolver)); } return(descriptor .Type <NativeType <TResult> >() .Resolver(ctx => Task.FromResult <object>(resolver(ctx)), typeof(NativeType <TResult>))); }
public static IObjectFieldDescriptor UseLimitOffsetPaging <TSchemaType>( this IObjectFieldDescriptor descriptor) where TSchemaType : class { descriptor .Type <PaginationPayloadType <TSchemaType> >() .Argument("pageIndex", a => a.Type <IntType>()) .Argument("pageSize", a => a.Type <IntType>()) .Use(next => async context => { await next(context); if (context.Result is IQueryable <TSchemaType> list) { var paginatedList = await PaginatedList <TSchemaType> .CreateAsync(list, context.Argument <int>("pageIndex"), context.Argument <int>("pageSize")); var result = new PaginationPayload <TSchemaType>(paginatedList.ToList(), paginatedList.HasNextPage, paginatedList.HasPreviousPage); context.Result = result; } }); return(descriptor); }
public static IObjectFieldDescriptor NonNullType <T>(this IObjectFieldDescriptor descriptor) where T : class, IOutputType { return(descriptor.Type <NonNullType <T> >()); }
public void ConfigFieldDescriptor(IObjectFieldDescriptor descriptor) { descriptor .Type <ListType <PaymentType> >() .Argument("last", a => a.Type <IdType>()); }
public static IObjectFieldDescriptor Type <TOutputType>(this IObjectFieldDescriptor descriptor, bool nullable) where TOutputType : class, IOutputType { return(nullable ? descriptor.Type <TOutputType>() : descriptor.Type <NonNullType <TOutputType> >()); }
internal static IObjectFieldDescriptor UseNamedApiResource <TResourceType, TSchemaType>(this IObjectFieldDescriptor descriptor) where TResourceType : NamedApiResource where TSchemaType : ObjectType <TResourceType> => descriptor.Type <TSchemaType>() .Argument("nameOrId", a => a.Type <NonNullType <StringType> >().Description("The identifier or name for the resource.")) .Resolver((ctx, token) => ctx.Service <PokeApiClient>().GetResourceFromParamAsync <TResourceType>(ctx.Argument <string>("nameOrId"), token));
internal static IObjectFieldDescriptor UseApiResource <TResourceType, TSchemaType>(this IObjectFieldDescriptor descriptor) where TResourceType : ApiResource where TSchemaType : ObjectType <TResourceType> => descriptor.Type <TSchemaType>() .Argument("id", a => a.Type <NonNullType <IntType> >().Description("The identifier for the resource.")) .Resolver((ctx, token) => ctx.Service <PokeApiClient>().GetResourceAsync <TResourceType>(ctx.Argument <int>("id"), token));