graphql-composer
Version:
Create your GraphQL API using composition!
86 lines (85 loc) • 3.57 kB
TypeScript
import { GraphQLField, FieldDefinitionNode } from "graphql";
import { Args, ResolveFunction, FieldType, StringKeyOf, InputField, KeyValue, ClassType, InputType, Context } from "../..";
import { GQLField } from "./GQLField";
export declare type SubscriptionFunction<ReturnType = any, ArgsType = KeyValue, SourceType = any> = (args: ArgsType, context: Context<ReturnType, SourceType>) => Promise<ReturnType> | ReturnType;
export declare class Field<NameType = string, ExtensionsType = any> extends GQLField<GraphQLField<any, any, any>, NameType, ExtensionsType> {
private _args;
private _doParseArgs;
private _resolver;
private _subscription;
private _middlewares;
get args(): Args<any, any>[];
get flatArgs(): import("./Arg").Arg<string, any>[];
get doParseArgs(): boolean;
get resolver(): ResolveFunction<any, KeyValue, any>;
get subscription(): SubscriptionFunction<any, KeyValue, any>;
get middlewares(): ResolveFunction<any, KeyValue, any>[];
get definitionNode(): FieldDefinitionNode;
protected constructor(name: NameType & string, type: FieldType);
/**
* Create a new Field for ObjectType and InterfaceType
*/
static create<NameType = any>(name: StringKeyOf<NameType>, type: FieldType): Field<StringKeyOf<NameType>>;
static create(name: string, type: FieldType): Field<string>;
static create<NameType = any>(field: InputField<any>): Field<StringKeyOf<NameType>>;
static create<NameType = any>(field: Field<any>): Field<StringKeyOf<NameType>>;
build(): GraphQLField<any, any, any>;
/**
* Set the middlewares to your field
* A middleware is executed before your main function
* @param middlewares The middlewares list
*/
setMiddlewares(...middlewares: ResolveFunction[]): this;
/**
* Add some middlewares to your field
* A middleware is executed before your main function
* @param middlewares The middlewares list
*/
addMiddlewares(...middlewares: ResolveFunction[]): this;
/**
* Remove some middlewares from your field
* @param middlewares The middlewares list
*/
removeMiddlewares(...middlewares: ResolveFunction[]): this;
/**
* If you don't want to parse your aguments objects into the specified class (enabled by default)
*/
disableArgsParsing(): this;
/**
* If you want to parse your aguments objects into the specified class (enabled by default)
*/
enableArgsParsing(): this;
/**
* Set the arguments of your field
* @param args The aguments
*/
setArgs(...args: Args[]): this;
/**
* Add arguments to your field
* @param args The aguments
*/
addArgs(...args: Args[]): this;
/**
* Set the resolver function to your field
* @param args The aguments
*/
setResolver<ReturnType = any, ArgType = KeyValue>(resolver: ResolveFunction<ReturnType, ArgType>, ...args: Args<ClassType<ArgType>>[]): this;
/**
* Set the resolver function to your field
* @param args The aguments
*/
setSubscription<ReturnType = any, ArgType = KeyValue>(subscription: SubscriptionFunction<ReturnType, ArgType>): this;
/**
* Copy the field and return a new one
*/
copy(): Field<NameType>;
/**
* Convert your field into a new field type
* @param to The target type
*/
convert(to: typeof InputField): InputField<NameType>;
protected parseArgs(args: (Args | InputType)[], values: KeyValue): any;
private resolveField;
private subscribe;
private next;
}