InputTypeComposer
Static methods
static create()
static create<TCtx = any>( typeDef: InputTypeComposerDefinition, schemaComposer: SchemaComposer<TCtx> ): InputTypeComposer<TCtx> Create InputTypeComposer with adding it by name to the SchemaComposer.
static createTemp()
static createTemp<TCtx = any>( typeDef: InputTypeComposerDefinition, schemaComposer: SchemaComposer<TCtx> ): InputTypeComposer<TCtx> Create InputTypeComposer without adding it to the SchemaComposer. This method may be useful in plugins, when you need to create type temporary.
Getters
List
List: ListComposer<InputTypeComposer<TContext>>; Get Type wrapped in List modifier
const UserTC = schemaComposer.createInputTC(`input UserInput { name: String }`); schemaComposer.Mutation.addFields({ add: { args: { users1: UserTC.List, // in SDL: users1: [UserInput] users2: UserTC.NonNull.List, // in SDL: users2: [UserInput!] users3: UserTC.NonNull.List.NonNull // in SDL: users2: [UserInput!]! } } }); NonNull
NonNull: NonNullComposer<InputTypeComposer<TContext>>; Get Type wrapped in NonNull modifier
const UserTC = schemaComposer.createInputTC(`input UserInput { name: String }`); schemaComposer.Mutation.addFields({ add: { args: { users1: UserTC.List, // in SDL: users1: [UserInput] users2: UserTC.NonNull.List, // in SDL: users2: [UserInput!] users3: UserTC.NonNull.List.NonNull // in SDL: users2: [UserInput!]! } } }); Properties
schemaComposer
schemaComposer: SchemaComposer<TContext>; Field methods
getFields()
getFields(): InputTypeComposerFieldConfigMap getFieldNames()
getFieldNames(): string[] hasField()
hasField( fieldName: string ): boolean setFields()
setFields( fields: InputTypeComposerFieldConfigMapDefinition ): this setField()
setField( fieldName: string, fieldConfig: InputTypeComposerFieldConfigDefinition ): this addFields()
addFields( newFields: InputTypeComposerFieldConfigMapDefinition ): this Add new fields or replace existed in a GraphQL type
addNestedFields()
addNestedFields( newFields: InputTypeComposerFieldConfigMapDefinition ): this Add new fields or replace existed (where field name may have dots)
getField()
getField( fieldName: string ): InputTypeComposerFieldConfig removeField()
removeField( fieldNameOrArray: string | string[] ): this Remove fields from type by name or array of names. You also may pass name in dot-notation, in such case will be removed nested field.
removeField('field1'); // remove 1 field removeField(['field1', 'field2']); // remove 2 fields removeField('field1.subField1'); // remove 1 nested field removeOtherFields()
removeOtherFields( fieldNameOrArray: string | string[] ): this extendField()
extendField( fieldName: string, partialFieldConfig: Partial<InputTypeComposerFieldConfigAsObjectDefinition> ): this reorderFields()
reorderFields( names: string[] ): this getFieldConfig()
getFieldConfig( fieldName: string ): GraphQLInputFieldConfig getFieldType()
getFieldType( fieldName: string ): GraphQLInputType getFieldTypeName()
getFieldTypeName( fieldName: string ): string getFieldTC()
getFieldTC( fieldName: string ): ComposeNamedInputType<TContext> Automatically unwrap from List, NonNull, ThunkComposer It's important! Cause greatly helps to modify fields types in a real code without manual unwrap writing.
If you need to work with wrappers, you may use the following code:
TC.getField().type// returns real wrapped TypeComposerTC.isFieldNonNull()// checks is field NonNull or notTC.makeFieldNonNull()// for wrapping in NonNullComposerTC.makeFieldNullable()// for unwrapping from NonNullComposerTC.isFieldPlural()// checks is field wrapped in ListComposer or notTC.makeFieldPlural()// for wrapping in ListComposerTC.makeFieldNonPlural()// for unwrapping from ListComposer
getFieldITC()
getFieldITC( fieldName: string ): InputTypeComposer<TContext> Alias for getFieldTC() but returns statically checked InputTypeComposer. If field have other type then error will be thrown.
isRequired()
isRequired( fieldName: string ): boolean isFieldNonNull()
isFieldNonNull( fieldName: string ): boolean makeFieldNonNull()
makeFieldNonNull( fieldNameOrArray: string | string[] ): this makeRequired()
makeRequired( fieldNameOrArray: string | string[] ): this An alias for makeFieldNonNull()
makeFieldNullable()
makeFieldNullable( fieldNameOrArray: string | string[] ): this makeOptional()
makeOptional( fieldNameOrArray: string | string[] ): this An alias for makeFieldNullable()
isFieldPlural()
isFieldPlural( fieldName: string ): boolean makeFieldPlural()
makeFieldPlural( fieldNameOrArray: string | string[] ): this makeFieldNonPlural()
makeFieldNonPlural( fieldNameOrArray: string | string[] ): this Type methods
getType()
getType(): GraphQLInputObjectType getTypePlural()
getTypePlural(): ListComposer<InputTypeComposer<TContext>> getTypeNonNull()
getTypeNonNull(): NonNullComposer<InputTypeComposer<TContext>> getTypeName()
getTypeName(): string setTypeName()
setTypeName( name: string ): this getDescription()
getDescription(): string setDescription()
setDescription( description: string ): this clone()
clone( newTypeNameOrTC: string | InputTypeComposer<any> ): InputTypeComposer<TContext> You may clone this type with a new provided name as string. Or you may provide a new TypeComposer which will get all cloned settings from this type.
cloneTo()
cloneTo( anotherSchemaComposer: SchemaComposer<any>, cloneMap: Map<any, any> ): InputTypeComposer<any> Clone this type to another SchemaComposer. Also will be cloned all sub-types.
merge()
merge( type: GraphQLInputObjectType | InputTypeComposer<any> ): this Extensions methods
Extensions is a property on type/field/arg definitions to pass private extra metadata. It's used only on the server-side with the Code-First approach, mostly for 3rd party server middlewares & plugins. Property extensions may contain private server metadata of any type (even functions) and does not available via SDL.
@see https://github.com/graphql/graphql-js/issues/1527 @note If you need to provide public metadata to clients then use directives instead.
getExtensions()
getExtensions(): Extensions setExtensions()
setExtensions( extensions: Extensions | undefined ): this extendExtensions()
extendExtensions( extensions: Extensions ): this clearExtensions()
clearExtensions(): this getExtension()
getExtension( extensionName: string ): unknown hasExtension()
hasExtension( extensionName: string ): boolean setExtension()
setExtension( extensionName: string, value: unknown ): this removeExtension()
removeExtension( extensionName: string ): this getFieldExtensions()
getFieldExtensions( fieldName: string ): Extensions setFieldExtensions()
setFieldExtensions( fieldName: string, extensions: Extensions ): this extendFieldExtensions()
extendFieldExtensions( fieldName: string, extensions: Extensions ): this clearFieldExtensions()
clearFieldExtensions( fieldName: string ): this getFieldExtension()
getFieldExtension( fieldName: string, extensionName: string ): unknown hasFieldExtension()
hasFieldExtension( fieldName: string, extensionName: string ): boolean setFieldExtension()
setFieldExtension( fieldName: string, extensionName: string, value: unknown ): this removeFieldExtension()
removeFieldExtension( fieldName: string, extensionName: string ): this Directive methods
Directives provide the ability to work with public metadata which is available via SDL. Directives can be used on type/field/arg definitions. The most famous directives are @deprecated(reason: "...") and @specifiedBy(url: "...") which are present in GraphQL spec. GraphQL spec allows to you add any own directives.
@example type Article @directive1 { name @directive2 comments(limit: Int @directive3) }
@note If you need private metadata then use extensions instead.
getDirectives()
getDirectives(): Array<Directive> setDirectives()
setDirectives( directives: Array<Directive> ): this getDirectiveNames()
getDirectiveNames(): string[] getDirectiveByName()
getDirectiveByName( directiveName: string ): DirectiveArgs | undefined Returns arguments of first found directive by name. If directive does not exists then will be returned undefined.
setDirectiveByName()
setDirectiveByName( directiveName: string, args: DirectiveArgs ): this Set arguments of first found directive by name. If directive does not exists then will be created new one.
getDirectiveById()
getDirectiveById( idx: number ): DirectiveArgs | undefined getFieldDirectives()
getFieldDirectives( fieldName: string ): Array<Directive> setFieldDirectives()
setFieldDirectives( fieldName: string, directives: Array<Directive> | undefined ): this getFieldDirectiveNames()
getFieldDirectiveNames( fieldName: string ): string[] getFieldDirectiveByName()
getFieldDirectiveByName( fieldName: string, directiveName: string ): DirectiveArgs | undefined Returns arguments of first found directive by name. If directive does not exists then will be returned undefined.
setFieldDirectiveByName()
setFieldDirectiveByName( fieldName: string, directiveName: string, args: DirectiveArgs ): this Set arguments of first found directive by name. If directive does not exists then will be created new one.
getFieldDirectiveById()
getFieldDirectiveById( fieldName: string, idx: number ): DirectiveArgs | undefined Misc methods
get()
get( path: string | string[] ): TypeInPath<TContext> | void getNestedTCs()
getNestedTCs( opts: { exclude?: string[] | null; }, passedTypes: Set<NamedTypeComposer<any>> ): Set<NamedTypeComposer<any>> Returns all types which are used inside the current type
toSDL()
toSDL( opts: SchemaPrinterOptions & { deep?: boolean; exclude?: string[]; } ): string Prints SDL for current type. Or print with all used types if deep: true option was provided.
Internal type definitions
InputTypeComposerDefinition
export type InputTypeComposerDefinition = | TypeAsString | TypeDefinitionString | InputTypeComposerAsObjectDefinition | Readonly<GraphQLInputObjectType>; InputTypeComposerAsObjectDefinition
export type InputTypeComposerAsObjectDefinition = { name: string; fields: ThunkWithSchemaComposer<InputTypeComposerFieldConfigMapDefinition, SchemaComposer<any>>; description?: null | string; extensions?: Extensions; directives?: Directive[]; }; InputTypeComposerFieldConfigMap
export type InputTypeComposerFieldConfigMap = ObjMap<InputTypeComposerFieldConfig>; InputTypeComposerFieldConfigMapDefinition
export type InputTypeComposerFieldConfigMapDefinition = ObjMap<InputTypeComposerFieldConfigDefinition>; InputTypeComposerFieldConfigDefinition
export type InputTypeComposerFieldConfigDefinition = | ThunkWithSchemaComposer<InputTypeComposerFieldConfigAsObjectDefinition, SchemaComposer<any>> | ThunkWithSchemaComposer<ComposeInputTypeDefinition, SchemaComposer<any>>; InputTypeComposerFieldConfigAsObjectDefinition
export type InputTypeComposerFieldConfigAsObjectDefinition = { type: ThunkWithSchemaComposer<ComposeInputTypeDefinition, SchemaComposer<any>>; defaultValue?: unknown; description?: string | null; extensions?: Extensions; directives?: Directive[]; [key: string]: unknown; }; InputTypeComposerFieldConfig
export type InputTypeComposerFieldConfig = { type: ComposeInputType; defaultValue?: unknown; description?: string | null; astNode?: InputValueDefinitionNode | null; extensions?: Extensions; directives?: Directive[]; [key: string]: unknown; }; InputTypeComposerThunked
export type InputTypeComposerThunked<TContext> = | InputTypeComposer<TContext> | ThunkComposer<InputTypeComposer<TContext>, GraphQLInputType>; 