UNPKG

5.24 kBTypeScriptView Raw
1import * as graphql from 'graphql';
2import { Scalar, Enum, EnumValue, ObjectType, InputObject, Interface, Union, InputType, OutputType, ArgMap, TOfArgMap, Field, AbstractField, DefaultArgument, Argument, InputFieldMap, SubscriptionField, SubscriptionObject } from './types';
3declare type ExtensionsMap = {
4 field?: {
5 [key: string]: any;
6 };
7 objectType?: {
8 [key: string]: any;
9 };
10};
11export declare type Factory<Ctx, TExtensionsMap extends ExtensionsMap> = {
12 String: Scalar<string | null>;
13 Int: Scalar<number | null>;
14 Float: Scalar<number | null>;
15 Boolean: Scalar<boolean | null>;
16 ID: Scalar<string | null>;
17 scalarType<Src>({ name, description, serialize, parseValue, parseLiteral, }: {
18 name: string;
19 description?: string | undefined;
20 serialize: (src: Src) => any;
21 parseValue?: ((value: JSON) => Src | null) | undefined;
22 parseLiteral?: ((value: graphql.ValueNode) => Src | null) | undefined;
23 }): Scalar<Src | null>;
24 enumType<Src>({ name, description, values, }: {
25 name: string;
26 description?: string | undefined;
27 values: EnumValue<Src>[];
28 }): Enum<Src | null>;
29 arg<Src>(type: InputType<Src>, description?: string | undefined): Argument<Src>;
30 defaultArg<Src>(type: InputType<Src>, defaultArg: Exclude<Src, null>, description?: string | undefined): DefaultArgument<Exclude<Src, null>>;
31 field<Src, Arg, Out>(name: string, { type, args, resolve, description, deprecationReason, extensions }: {
32 type: OutputType<Ctx, Out>;
33 args?: ArgMap<Arg> | undefined;
34 description?: string | undefined;
35 deprecationReason?: string | undefined;
36 resolve: (src: Src, args: TOfArgMap<ArgMap<Arg>>, ctx: Ctx, info: graphql.GraphQLResolveInfo) => Out | Promise<Out>;
37 extensions?: TExtensionsMap['field'];
38 }): Field<Ctx, Src, any, any>;
39 defaultField<Src extends object, K extends keyof Src>(name: K, type: OutputType<Ctx, Src[K]>, opts?: {
40 description?: string | undefined;
41 deprecationReason?: string | undefined;
42 } | undefined): Field<Ctx, Src, any, any>;
43 abstractField<Out_1>(name: string, type: OutputType<Ctx, Out_1>, opts?: {
44 description?: string | undefined;
45 deprecationReason?: string | undefined;
46 } | undefined): AbstractField<Ctx, Out_1>;
47 objectType<Src, Ctx = any>({ name, description, interfaces, fields, isTypeOf, extensions, }: {
48 name: string;
49 description?: string | undefined;
50 interfaces?: Interface<Ctx, any>[] | undefined;
51 fields: (self: OutputType<Ctx, Src | null>) => Field<Ctx, Src, any, {}>[];
52 isTypeOf?: ((src: any, ctx: Ctx, info: graphql.GraphQLResolveInfo) => boolean) | undefined;
53 extensions?: TExtensionsMap['objectType'];
54 }): ObjectType<Ctx, Src | null>;
55 inputObjectType<Src>({ name, description, fields, }: {
56 name: string;
57 description?: string | undefined;
58 fields: (self: InputType<Src | null>) => InputFieldMap<Src>;
59 }): InputObject<Src | null>;
60 unionType<Src>({ name, types, resolveType, }: {
61 name: string;
62 types: ObjectType<Ctx, any>[];
63 resolveType: (src: Src) => ObjectType<any, any>;
64 }): Union<Ctx, Src | null>;
65 interfaceType<Src>({ name, description, interfaces, fields, }: {
66 name: string;
67 description?: string | undefined;
68 interfaces?: Interface<Ctx, any>[] | undefined;
69 fields: (self: Interface<Ctx, Src | null>) => AbstractField<Ctx, any>[];
70 }): Interface<Ctx, Src | null>;
71 List<Src>(ofType: OutputType<Ctx, Src>): OutputType<Ctx, Src[] | null>;
72 ListInput<Src>(ofType: InputType<Src>): InputType<Src[] | null>;
73 NonNull<Src>(ofType: OutputType<Ctx, Src | null>): OutputType<Ctx, Src>;
74 NonNullInput<Src>(ofType: InputType<Src | null>): InputType<Src>;
75 queryType<RootSrc>({ name, fields, }: {
76 name?: string | undefined;
77 fields: Field<Ctx, RootSrc, any, {}>[];
78 }): ObjectType<Ctx, RootSrc>;
79 mutationType<RootSrc>({ name, fields, }: {
80 name?: string | undefined;
81 fields: () => Field<Ctx, RootSrc, any, {}>[];
82 }): ObjectType<Ctx, RootSrc>;
83 subscriptionField<RootSrc, Out_2, Arg_1>(name: string, { type, args, subscribe, resolve, description, deprecationReason, }: {
84 type: OutputType<Ctx, Out_2>;
85 args?: ArgMap<Arg_1> | undefined;
86 description?: string | undefined;
87 deprecationReason?: string | undefined;
88 subscribe: (src: RootSrc, args: TOfArgMap<ArgMap<Arg_1>>, ctx: Ctx, info: graphql.GraphQLResolveInfo) => AsyncIterator<Out_2, any, undefined> | Promise<AsyncIterator<Out_2, any, undefined>>;
89 resolve?: ((src: RootSrc, args: TOfArgMap<ArgMap<Arg_1>>, ctx: Ctx, info: graphql.GraphQLResolveInfo) => Out_2 | Promise<Out_2>) | undefined;
90 }): SubscriptionField<Ctx, RootSrc, Arg_1, Out_2>;
91 subscriptionType<Src>({ name, fields, }: {
92 name?: string | undefined;
93 fields: SubscriptionField<Ctx, Src, unknown, unknown>[];
94 }): SubscriptionObject<Ctx, Src>;
95};
96export declare function createTypesFactory<Ctx = undefined, TExtensions extends ExtensionsMap = {}>(): Factory<Ctx, TExtensions>;
97export {};
98
\No newline at end of file