UNPKG

18.2 kBTypeScriptView Raw
1import { GraphQLObjectType, GraphQLInputObjectType, GraphQLInterfaceType } from './graphql';
2import type { GraphQLFieldConfig, GraphQLOutputType, GraphQLInputType, GraphQLIsTypeOfFn, GraphQLResolveInfo, GraphQLFieldResolver, FieldDefinitionNode, InputValueDefinitionNode } from './graphql';
3import { InputTypeComposer } from './InputTypeComposer';
4import type { TypeAsString, TypeDefinitionString } from './TypeMapper';
5import { InterfaceTypeComposer, InterfaceTypeComposerDefinition, InterfaceTypeComposerThunked } from './InterfaceTypeComposer';
6import { Resolver, ResolverDefinition, ResolverNextRpCb, ResolverWrapCb, ResolverMiddleware } from './Resolver';
7import { SchemaComposer } from './SchemaComposer';
8import { ListComposer } from './ListComposer';
9import { NonNullComposer } from './NonNullComposer';
10import { ThunkComposer } from './ThunkComposer';
11import type { ToInputTypeOpts } from './utils/toInputType';
12import { TypeInPath } from './utils/typeByPath';
13import { NamedTypeComposer } from './utils/typeHelpers';
14import type { ProjectionType } from './utils/projection';
15import type { ObjMap, ThunkWithSchemaComposer, Extensions, Directive, DirectiveArgs } from './utils/definitions';
16import type { ComposeNamedInputType, ComposeInputType, ComposeInputTypeDefinition, ComposeOutputTypeDefinition, ComposeOutputType, ComposeNamedOutputType } from './utils/typeHelpers';
17import { SchemaPrinterOptions } from './utils/schemaPrinter';
18export declare type ObjectTypeComposerDefinition<TSource, TContext> = TypeAsString | TypeDefinitionString | ObjectTypeComposerAsObjectDefinition<TSource, TContext> | Readonly<ObjectTypeComposer<TSource, TContext>> | Readonly<GraphQLObjectType>;
19export declare type ObjectTypeComposerAsObjectDefinition<TSource, TContext> = {
20 name: string;
21 interfaces?: null | ThunkWithSchemaComposer<ReadonlyArray<InterfaceTypeComposerDefinition<any, TContext>>, SchemaComposer<TContext>>;
22 fields?: ObjectTypeComposerFieldConfigMapDefinition<TSource, TContext>;
23 isTypeOf?: null | GraphQLIsTypeOfFn<TSource, TContext>;
24 description?: string | null;
25 isIntrospection?: boolean;
26 extensions?: Extensions;
27 directives?: Directive[];
28};
29export declare type ObjectTypeComposerFieldConfigMap<TSource, TContext> = ObjMap<ObjectTypeComposerFieldConfig<TSource, TContext>>;
30export declare type ObjectTypeComposerFieldConfigMapDefinition<TSource, TContext> = ObjMap<ObjectTypeComposerFieldConfigDefinition<TSource, TContext>>;
31export declare type ObjectTypeComposerFieldConfigDefinition<TSource, TContext, TArgs = any> = ThunkWithSchemaComposer<ObjectTypeComposerFieldConfigAsObjectDefinition<TSource, TContext, TArgs>, SchemaComposer<TContext>> | ThunkWithSchemaComposer<ComposeOutputTypeDefinition<TContext>, SchemaComposer<TContext>>;
32export declare type ObjectTypeComposerFieldConfigAsObjectDefinition<TSource, TContext, TArgs = any> = {
33 type: ThunkWithSchemaComposer<ComposeOutputTypeDefinition<TContext> | Readonly<Resolver<any, TContext, any>>, SchemaComposer<TContext>>;
34 args?: ObjectTypeComposerArgumentConfigMapDefinition<TArgs>;
35 resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>;
36 subscribe?: GraphQLFieldResolver<TSource, TContext>;
37 deprecationReason?: string | null;
38 description?: string | null;
39 extensions?: Extensions | undefined;
40 directives?: Directive[];
41 [key: string]: any;
42};
43export declare type ObjectTypeComposerFieldConfig<TSource, TContext, TArgs = any> = {
44 type: ComposeOutputType<TContext>;
45 args?: ObjectTypeComposerArgumentConfigMap<TArgs>;
46 resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>;
47 subscribe?: GraphQLFieldResolver<TSource, TContext>;
48 deprecationReason?: string | null;
49 description?: string | null;
50 astNode?: FieldDefinitionNode | null;
51 extensions?: Extensions;
52 directives?: Directive[];
53 [key: string]: any;
54};
55export declare type ObjectTypeComposerArgumentConfigMap<TArgs = Record<string, any>> = Record<keyof TArgs, ObjectTypeComposerArgumentConfig>;
56export declare type ObjectTypeComposerArgumentConfigMapDefinition<TArgs = Record<string, any>> = Record<keyof TArgs, ObjectTypeComposerArgumentConfigDefinition>;
57export declare type ObjectTypeComposerArgumentConfigAsObjectDefinition = {
58 type: ThunkWithSchemaComposer<ComposeInputTypeDefinition, SchemaComposer<any>>;
59 defaultValue?: any;
60 description?: string | null;
61 deprecationReason?: string | null;
62 extensions?: Extensions;
63 directives?: Directive[];
64 [key: string]: any;
65};
66export declare type ObjectTypeComposerArgumentConfig = {
67 type: ComposeInputType;
68 defaultValue?: any;
69 description?: string | null;
70 deprecationReason?: string | null;
71 astNode?: InputValueDefinitionNode | null;
72 extensions?: Extensions;
73 directives?: Directive[];
74 [key: string]: any;
75};
76export declare type ObjectTypeComposerArgumentConfigDefinition = ObjectTypeComposerArgumentConfigAsObjectDefinition | ThunkWithSchemaComposer<ComposeInputTypeDefinition, SchemaComposer<any>>;
77export declare type ObjectTypeComposerRelationMap<TSource, TContext> = {
78 [fieldName: string]: ObjectTypeComposerRelationOpts<any, TSource, TContext>;
79};
80export declare type ObjectTypeComposerRelationOpts<TRelationSource, TSource, TContext, TArgs extends Record<string, any> = any> = ObjectTypeComposerRelationOptsWithResolver<TRelationSource, TSource, TContext, TArgs> | ObjectTypeComposerFieldConfigAsObjectDefinition<TSource, TContext, TArgs>;
81export declare type ObjectTypeComposerRelationOptsWithResolver<TRelationSource, TSource, TContext, TArgs extends Record<string, any> = any> = {
82 resolver: ThunkWithSchemaComposer<Resolver<TRelationSource, TContext, TArgs>, SchemaComposer<TContext>>;
83 prepareArgs?: ObjectTypeComposerRelationArgsMapper<TSource, TContext, TArgs>;
84 projection?: ProjectionType;
85 description?: string | null;
86 deprecationReason?: string | null;
87 catchErrors?: boolean;
88 extensions?: Extensions;
89 directives?: Directive[];
90};
91export declare type ObjectTypeComposerRelationArgsMapperFn<TSource, TContext, TArgs = Record<string, any>> = (source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo) => any;
92export declare type ObjectTypeComposerRelationArgsMapper<TSource, TContext, TArgs extends Record<string, any> = Record<string, any>> = {
93 [argName in keyof TArgs]: {
94 [key: string]: any;
95 } | ObjectTypeComposerRelationArgsMapperFn<TSource, TContext, TArgs> | null | void | string | number | any[];
96};
97export declare type ObjectTypeComposerGetRecordIdFn<TSource, TContext, TArgs = any> = (source: TSource, args?: TArgs, context?: TContext) => string;
98export declare type ObjectTypeComposerThunked<TReturn, TContext> = ObjectTypeComposer<TReturn, TContext> | ThunkComposer<ObjectTypeComposer<TReturn, TContext>, GraphQLObjectType>;
99export declare class ObjectTypeComposer<TSource = any, TContext = any> {
100 schemaComposer: SchemaComposer<TContext>;
101 _gqType: GraphQLObjectType;
102 _gqcInputTypeComposer: undefined | InputTypeComposer<TContext>;
103 _gqcResolvers: undefined | Map<string, Resolver<TSource, TContext>>;
104 _gqcGetRecordIdFn: undefined | ObjectTypeComposerGetRecordIdFn<TSource, TContext>;
105 _gqcRelations: undefined | ObjectTypeComposerRelationMap<TSource, TContext>;
106 _gqcFields: ObjectTypeComposerFieldConfigMap<TSource, TContext>;
107 _gqcInterfaces: Array<InterfaceTypeComposerThunked<TSource, TContext>>;
108 _gqcExtensions?: Extensions;
109 _gqcDirectives?: Directive[];
110 _gqcIsModified?: boolean;
111 static create<TSrc = any, TCtx = any>(typeDef: ObjectTypeComposerDefinition<TSrc, TCtx>, schemaComposer: SchemaComposer<TCtx>): ObjectTypeComposer<TSrc, TCtx>;
112 static createTemp<TSrc = any, TCtx = any>(typeDef: ObjectTypeComposerDefinition<TSrc, TCtx>, schemaComposer?: SchemaComposer<TCtx>): ObjectTypeComposer<TSrc, TCtx>;
113 constructor(graphqlType: GraphQLObjectType, schemaComposer: SchemaComposer<TContext>);
114 getFields(): ObjectTypeComposerFieldConfigMap<TSource, TContext>;
115 getFieldNames(): string[];
116 getField<TArgs = any>(fieldName: string): ObjectTypeComposerFieldConfig<TSource, TContext, TArgs>;
117 hasField(fieldName: string): boolean;
118 setFields(fields: ObjectTypeComposerFieldConfigMapDefinition<TSource, TContext>): this;
119 setField<TArgs = any>(fieldName: string, fieldConfig: ObjectTypeComposerFieldConfigDefinition<TSource, TContext, TArgs>): this;
120 addFields(newFields: ObjectTypeComposerFieldConfigMapDefinition<TSource, TContext>): this;
121 addNestedFields(newFields: ObjectTypeComposerFieldConfigMapDefinition<TSource, TContext>): this;
122 removeField(fieldNameOrArray: string | string[]): this;
123 removeOtherFields(fieldNameOrArray: string | string[]): this;
124 reorderFields(names: string[]): this;
125 extendField<TArgs = any>(fieldName: string, partialFieldConfig: Partial<ObjectTypeComposerFieldConfigAsObjectDefinition<TSource, TContext, TArgs>>): this;
126 getFieldConfig(fieldName: string): GraphQLFieldConfig<TSource, TContext>;
127 getFieldType(fieldName: string): GraphQLOutputType;
128 getFieldTypeName(fieldName: string): string;
129 getFieldTC(fieldName: string): ComposeNamedOutputType<TContext>;
130 getFieldOTC(fieldName: string): ObjectTypeComposer<TSource, TContext>;
131 isFieldNonNull(fieldName: string): boolean;
132 makeFieldNonNull(fieldNameOrArray: string | string[]): this;
133 makeFieldNullable(fieldNameOrArray: string | string[]): this;
134 isFieldPlural(fieldName: string): boolean;
135 makeFieldPlural(fieldNameOrArray: string | string[]): this;
136 makeFieldNonPlural(fieldNameOrArray: string | string[]): this;
137 deprecateFields(fields: {
138 [fieldName: string]: string;
139 } | string[] | string): this;
140 getFieldArgs<TArgs = any>(fieldName: string): ObjectTypeComposerArgumentConfigMap<TArgs>;
141 getFieldArgNames(fieldName: string): string[];
142 hasFieldArg(fieldName: string, argName: string): boolean;
143 getFieldArg(fieldName: string, argName: string): ObjectTypeComposerArgumentConfig;
144 getFieldArgType(fieldName: string, argName: string): GraphQLInputType;
145 getFieldArgTypeName(fieldName: string, argName: string): string;
146 getFieldArgTC(fieldName: string, argName: string): ComposeNamedInputType<TContext>;
147 getFieldArgITC(fieldName: string, argName: string): InputTypeComposer<TContext>;
148 setFieldArgs(fieldName: string, args: ObjectTypeComposerArgumentConfigMapDefinition<any>): this;
149 addFieldArgs(fieldName: string, newArgs: ObjectTypeComposerArgumentConfigMapDefinition<any>): this;
150 setFieldArg(fieldName: string, argName: string, argConfig: ObjectTypeComposerArgumentConfigDefinition): this;
151 removeFieldArg(fieldName: string, argNameOrArray: string | string[]): this;
152 removeFieldOtherArgs(fieldName: string, argNameOrArray: string | string[]): this;
153 isFieldArgPlural(fieldName: string, argName: string): boolean;
154 makeFieldArgPlural(fieldName: string, argNameOrArray: string | string[]): this;
155 makeFieldArgNonPlural(fieldName: string, argNameOrArray: string | string[]): this;
156 isFieldArgNonNull(fieldName: string, argName: string): boolean;
157 makeFieldArgNonNull(fieldName: string, argNameOrArray: string | string[]): this;
158 makeFieldArgNullable(fieldName: string, argNameOrArray: string | string[]): this;
159 getType(): GraphQLObjectType;
160 getTypePlural(): ListComposer<ObjectTypeComposer<TSource, TContext>>;
161 getTypeNonNull(): NonNullComposer<ObjectTypeComposer<TSource, TContext>>;
162 get List(): ListComposer<ObjectTypeComposer<TSource, TContext>>;
163 get NonNull(): NonNullComposer<ObjectTypeComposer<TSource, TContext>>;
164 getTypeName(): string;
165 setTypeName(name: string): this;
166 getDescription(): string;
167 setDescription(description: string): this;
168 clone(newTypeNameOrTC: string | ObjectTypeComposer<any, any>): ObjectTypeComposer<TSource, TContext>;
169 cloneTo(anotherSchemaComposer: SchemaComposer<any>, cloneMap?: Map<any, any>): ObjectTypeComposer<any, any>;
170 getIsTypeOf(): GraphQLIsTypeOfFn<TSource, TContext> | undefined | null;
171 setIsTypeOf(fn: GraphQLIsTypeOfFn<any, any> | null | undefined): this;
172 merge(type: GraphQLObjectType | GraphQLInterfaceType | ObjectTypeComposer<any, any> | InterfaceTypeComposer<any, any>): this;
173 getInputType(): GraphQLInputObjectType;
174 hasInputTypeComposer(): boolean;
175 setInputTypeComposer(itc: InputTypeComposer<TContext>): this;
176 getInputTypeComposer(opts?: ToInputTypeOpts): InputTypeComposer<TContext>;
177 getITC(opts?: ToInputTypeOpts): InputTypeComposer<TContext>;
178 removeInputTypeComposer(): this;
179 getResolvers(): Map<string, Resolver<any, TContext, any>>;
180 hasResolver(name: string): boolean;
181 getResolver<TArgs = any>(name: string, middlewares?: Array<ResolverMiddleware<TSource, TContext, TArgs>>): Resolver<any, TContext, TArgs>;
182 setResolver(name: string, resolver: Resolver<any, TContext>): this;
183 addResolver(opts: Resolver<any, TContext> | ResolverDefinition<any, TContext>): this;
184 removeResolver(resolverName: string): this;
185 wrapResolver(resolverName: string, cbResolver: ResolverWrapCb<any, TSource, TContext>): this;
186 wrapResolverAs(resolverName: string, fromResolverName: string, cbResolver: ResolverWrapCb<any, TSource, TContext>): this;
187 wrapResolverResolve(resolverName: string, cbNextRp: ResolverNextRpCb<any, TContext>): this;
188 getInterfaces(): Array<InterfaceTypeComposerThunked<TSource, TContext>>;
189 getInterfacesTypes(): Array<GraphQLInterfaceType>;
190 setInterfaces(interfaces: ReadonlyArray<InterfaceTypeComposerDefinition<any, TContext>>): this;
191 hasInterface(iface: InterfaceTypeComposerDefinition<any, TContext>): boolean;
192 addInterface(iface: InterfaceTypeComposerDefinition<any, TContext> | InterfaceTypeComposerThunked<any, TContext>): this;
193 addInterfaces(ifaces: ReadonlyArray<InterfaceTypeComposerDefinition<any, TContext> | InterfaceTypeComposerThunked<any, TContext>>): this;
194 removeInterface(iface: InterfaceTypeComposerDefinition<any, TContext>): this;
195 getExtensions(): Extensions;
196 setExtensions(extensions: Extensions | undefined): this;
197 extendExtensions(extensions: Extensions): this;
198 clearExtensions(): this;
199 getExtension(extensionName: string): unknown;
200 hasExtension(extensionName: string): boolean;
201 setExtension(extensionName: string, value: unknown): this;
202 removeExtension(extensionName: string): this;
203 getFieldExtensions(fieldName: string): Extensions;
204 setFieldExtensions(fieldName: string, extensions: Extensions): this;
205 extendFieldExtensions(fieldName: string, extensions: Extensions): this;
206 clearFieldExtensions(fieldName: string): this;
207 getFieldExtension(fieldName: string, extensionName: string): unknown;
208 hasFieldExtension(fieldName: string, extensionName: string): boolean;
209 setFieldExtension(fieldName: string, extensionName: string, value: unknown): this;
210 removeFieldExtension(fieldName: string, extensionName: string): this;
211 getFieldArgExtensions(fieldName: string, argName: string): Extensions;
212 setFieldArgExtensions(fieldName: string, argName: string, extensions: Extensions): this;
213 extendFieldArgExtensions(fieldName: string, argName: string, extensions: Extensions): this;
214 clearFieldArgExtensions(fieldName: string, argName: string): this;
215 getFieldArgExtension(fieldName: string, argName: string, extensionName: string): unknown;
216 hasFieldArgExtension(fieldName: string, argName: string, extensionName: string): boolean;
217 setFieldArgExtension(fieldName: string, argName: string, extensionName: string, value: unknown): this;
218 removeFieldArgExtension(fieldName: string, argName: string, extensionName: string): this;
219 getDirectives(): Array<Directive>;
220 setDirectives(directives: Array<Directive>): this;
221 getDirectiveNames(): string[];
222 getDirectiveByName(directiveName: string): DirectiveArgs | undefined;
223 setDirectiveByName(directiveName: string, args?: DirectiveArgs): this;
224 getDirectiveById(idx: number): DirectiveArgs | undefined;
225 getFieldDirectives(fieldName: string): Array<Directive>;
226 setFieldDirectives(fieldName: string, directives: Array<Directive> | undefined): this;
227 getFieldDirectiveNames(fieldName: string): string[];
228 getFieldDirectiveByName(fieldName: string, directiveName: string): DirectiveArgs | undefined;
229 setFieldDirectiveByName(fieldName: string, directiveName: string, args?: DirectiveArgs): this;
230 getFieldDirectiveById(fieldName: string, idx: number): DirectiveArgs | undefined;
231 getFieldArgDirectives(fieldName: string, argName: string): Array<Directive>;
232 setFieldArgDirectives(fieldName: string, argName: string, directives: Array<Directive>): this;
233 getFieldArgDirectiveNames(fieldName: string, argName: string): string[];
234 getFieldArgDirectiveByName(fieldName: string, argName: string, directiveName: string): DirectiveArgs | undefined;
235 setFieldArgDirectiveByName(fieldName: string, argName: string, directiveName: string, args?: DirectiveArgs): this;
236 getFieldArgDirectiveById(fieldName: string, argName: string, idx: number): DirectiveArgs | undefined;
237 addRelation<TArgs extends Record<string, any> = any>(fieldName: string, opts: Readonly<ObjectTypeComposerRelationOpts<any, TSource, TContext, TArgs>>): this;
238 getRelations(): ObjectTypeComposerRelationMap<any, TContext>;
239 _relationWithResolverToFC(opts: ObjectTypeComposerRelationOptsWithResolver<any, TSource, TContext, any>, fieldName?: string): ObjectTypeComposerFieldConfig<TSource, TContext, any>;
240 setRecordIdFn(fn: ObjectTypeComposerGetRecordIdFn<TSource, TContext>): this;
241 hasRecordIdFn(): boolean;
242 getRecordIdFn(): ObjectTypeComposerGetRecordIdFn<TSource, TContext>;
243 getRecordId(source: TSource, args?: Record<string, any>, context?: TContext): string | number;
244 get(path: string | string[]): TypeInPath<TContext> | void;
245 getNestedTCs(opts?: {
246 exclude?: string[];
247 }, passedTypes?: Set<NamedTypeComposer<any>>): Set<NamedTypeComposer<any>>;
248 toSDL(opts?: SchemaPrinterOptions & {
249 deep?: boolean;
250 exclude?: string[];
251 }): string;
252}
253//# sourceMappingURL=ObjectTypeComposer.d.ts.map
\No newline at end of file