ScalarTypeComposer
ScalarTypeComposer
is a class which helps to create and modify GraphQLScalarType
.
Static methods
static create()
static create<TCtx = any, TInternal = any, TExternal = any>(
typeDef: ScalarTypeComposerDefinition<TInternal, TExternal>,
schemaComposer: SchemaComposer<TCtx>
): ScalarTypeComposer<TCtx>
Create ScalarTypeComposer
with adding it by name to the SchemaComposer
.
This type became available in SDL by its name.
static createTemp()
static createTemp<TCtx = any, TInternal = any, TExternal = any>(
typeDef: ScalarTypeComposerDefinition<TInternal, TExternal>,
schemaComposer: SchemaComposer<TCtx>
): ScalarTypeComposer<TCtx>
Create ScalarTypeComposer
without adding it to the SchemaComposer
.
This method may be useful in plugins, when you need to create type temporary.
Getters
List
List: ListComposer<ScalarTypeComposer<TContext>>;
Get Type wrapped in List modifier
const ColorTC = schemaComposer.createScalarTC(`scalar Color`);
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<ScalarTypeComposer<TContext>>;
Get Type wrapped in NonNull modifier
const ColorTC = schemaComposer.createScalarTC(`scalar Color`);
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>;
Serialize methods
setSerialize()
setSerialize(
fn: GraphQLScalarSerializer<any>
): this
getSerialize()
getSerialize(): GraphQLScalarSerializer<any>
setParseValue()
setParseValue(
fn: GraphQLScalarValueParser<any> | undefined
): this
getParseValue()
getParseValue(): GraphQLScalarValueParser<any> | undefined
setParseLiteral()
setParseLiteral(
fn: GraphQLScalarLiteralParser<any> | undefined
): this
getParseLiteral()
getParseLiteral(): GraphQLScalarLiteralParser<any> | undefined
Type methods
getType()
getType(): GraphQLScalarType
getTypePlural()
getTypePlural(): ListComposer<ScalarTypeComposer<TContext>>
getTypeNonNull()
getTypeNonNull(): NonNullComposer<ScalarTypeComposer<TContext>>
getTypeName()
getTypeName(): string
setTypeName()
setTypeName(
name: string
): this
getDescription()
getDescription(): string
setDescription()
setDescription(
description: string
): this
getSpecifiedByUrl()
getSpecifiedByUrl(): string | undefined | null
setSpecifiedByUrl()
setSpecifiedByUrl(
url: string | undefined | null
): this
clone()
clone(
newTypeNameOrTC: string | ScalarTypeComposer<any>
): ScalarTypeComposer<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>
): ScalarTypeComposer<any>
Copy this scalar type to another SchemaComposer.
Scalar types cannot be cloned. It will be very strange if we clone for example Boolean or Date types.
This methods exists for compatibility with other TypeComposers.
merge()
merge(
type: GraphQLScalarType | ScalarTypeComposer<any>
): ScalarTypeComposer<TContext>
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 | null
): 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
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
Misc methods
toSDL()
toSDL(
opts: SchemaPrinterOptions
): string
Prints SDL for current type.
Internal type definitions
ScalarTypeComposerDefinition
export type ScalarTypeComposerDefinition<TInternal, TExternal> =
| TypeAsString
| Readonly<ScalarTypeComposerAsObjectDefinition<TInternal, TExternal>>
| Readonly<GraphQLScalarType>;
ScalarTypeComposerAsObjectDefinition
export type ScalarTypeComposerAsObjectDefinition<TInternal, TExternal> = GraphQLScalarTypeConfig<
TInternal,
TExternal
> & {
extensions?: Extensions;
directives?: Directive[];
};