EnumTypeComposer
EnumTypeComposer
is a class which helps to create and modify GraphQLEnumType
.
Static methods
static create()
static create<TCtx = any>(
typeDef: EnumTypeComposerDefinition,
schemaComposer: SchemaComposer<TCtx>
): EnumTypeComposer<TCtx>
Create EnumTypeComposer
with adding it by name to the SchemaComposer
. This type became available in SDL by its name.
static createTemp()
static createTemp<TCtx = any>(
typeDef: EnumTypeComposerDefinition,
schemaComposer: SchemaComposer<TCtx>
): EnumTypeComposer<TCtx>
Create EnumTypeComposer
without adding it to the SchemaComposer
. This method may be useful in plugins, when you need to create type temporary.
Getters
List
List: ListComposer<EnumTypeComposer<TContext>>;
Get Type wrapped in List modifier
const ColorTC = schemaComposer.createEnumTC(`enum Color { RED GREEN }`);
schemaComposer.Query.addFields({
color1: { type: ColorTC.List }, // in SDL: color1: [Color]
color2: { type: ColorTC.NonNull.List }, // in SDL: color2: [Color!]
color3: { type: ColorTC.NonNull.List.NonNull } // in SDL: color2: [Color!]!
});
NonNull
NonNull: NonNullComposer<EnumTypeComposer<TContext>>;
Get Type wrapped in NonNull modifier
const ColorTC = schemaComposer.createEnumTC(`enum Color { RED GREEN }`);
schemaComposer.Query.addFields({
color1: { type: ColorTC.List }, // in SDL: color1: [Color]
color2: { type: ColorTC.NonNull.List }, // in SDL: color2: [Color!]
color3: { type: ColorTC.NonNull.List.NonNull } // in SDL: color2: [Color!]!
});
Properties
schemaComposer
schemaComposer: SchemaComposer<TContext>;
Value methods
hasField()
hasField(
name: string
): boolean
For similar naming with ObjectTypeComposer
and InputTypeComposer
for working with Enum values used methods with name *field*
instead of *value*
.
getFields()
getFields(): EnumTypeComposerValueConfigMap
getField()
getField(
name: string
): EnumTypeComposerValueConfig
getFieldNames()
getFieldNames(): string[]
setFields()
setFields(
values: EnumTypeComposerValueConfigMapDefinition
): this
Completely replace all values in the type with a new set.
setField()
setField(
name: string,
valueConfig: EnumTypeComposerValueConfigDefinition
): this
addFields()
addFields(
newValues: EnumTypeComposerValueConfigMapDefinition
): this
Add new fields or replace existed, other fields keep untouched.
removeField()
removeField(
nameOrArray: string | string[]
): this
Remove one value by its name, or by array of field names.
removeOtherFields()
removeOtherFields(
fieldNameOrArray: string | string[]
): this
Keep only provided fields in type, other fields will be removed.
reorderFields()
reorderFields(
names: string[]
): this
extendField()
extendField(
name: string,
partialValueConfig: Partial<EnumTypeComposerValueConfigDefinition>
): this
deprecateFields()
deprecateFields(
fields: {
[fieldName: string]: string;
} | string[] | string
): this
Mark value or map of values as deprecated
Type methods
getType()
getType(): GraphQLEnumType
getTypePlural()
getTypePlural(): ListComposer<EnumTypeComposer<TContext>>
getTypeNonNull()
getTypeNonNull(): NonNullComposer<EnumTypeComposer<TContext>>
getTypeName()
getTypeName(): string
setTypeName()
setTypeName(
name: string
): this
getDescription()
getDescription(): string
setDescription()
setDescription(
description: string
): this
clone()
clone(
newTypeNameOrTC: string | EnumTypeComposer<any>
): EnumTypeComposer<any>
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>
): EnumTypeComposer<any>
Clone this type to another SchemaComposer.
merge()
merge(
type: GraphQLEnumType | EnumTypeComposer<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
toSDL()
toSDL(
opts: SchemaPrinterOptions
): string
Prints SDL for current type.
Internal type definitions
EnumTypeComposerDefinition
export type EnumTypeComposerDefinition =
| TypeAsString
| EnumTypeComposerAsObjectDefinition
| GraphQLEnumType;
EnumTypeComposerAsObjectDefinition
export type EnumTypeComposerAsObjectDefinition = {
name: string;
values?: EnumTypeComposerValueConfigMapDefinition;
description?: string | null;
extensions?: Extensions;
directives?: Directive[];
};
EnumTypeComposerValueConfig
export type EnumTypeComposerValueConfig = {
value: any /* T */;
deprecationReason?: string | null;
description?: string | null;
astNode?: EnumValueDefinitionNode | null | undefined;
extensions?: Extensions;
directives?: Directive[];
[key: string]: any;
};
EnumTypeComposerValueConfigDefinition
export type EnumTypeComposerValueConfigDefinition = {
value?: any;
deprecationReason?: string | null;
description?: string | null;
extensions?: Extensions;
directives?: Directive[];
[key: string]: any;
};
EnumTypeComposerValueConfigMap
export type EnumTypeComposerValueConfigMap = ObjMap<EnumTypeComposerValueConfig>;
EnumTypeComposerValueConfigMapDefinition
export type EnumTypeComposerValueConfigMapDefinition =
ObjMapReadOnly<EnumTypeComposerValueConfigDefinition>;