Skip to main content

TypeDef

API reference

A definition of a parameter or return type in a Module.

Implements Node

id
A unique identifier for this TypeDef.
kind
The kind of type this is (e.g. primitive, list, object).
name
The canonical non-optional name of the type.
optional
Whether this type can be set to null. Defaults to false.
asEnum
If kind is ENUM, the enum-specific type definition. If kind is not ENUM, this will be null.
asInput
If kind is INPUT, the input-specific type definition. If kind is not INPUT, this will be null.
asInterface
If kind is INTERFACE, the interface-specific type definition. If kind is not INTERFACE, this will be null.
asList
If kind is LIST, the list-specific type definition. If kind is not LIST, this will be null.
asObject
If kind is OBJECT, the object-specific type definition. If kind is not OBJECT, this will be null.
asScalar
If kind is SCALAR, the scalar-specific type definition. If kind is not SCALAR, this will be null.
withConstructor
Adds a function for constructing a new instance of an Object TypeDef, failing if the type is not an object.
withEnum
Returns a TypeDef of kind Enum with the provided name.
withEnumMember
Adds a static value for an Enum TypeDef, failing if the type is not an enum.
withEnumValue
Adds a static value for an Enum TypeDef, failing if the type is not an enum.
withField
Adds a static field for an Object TypeDef, failing if the type is not an object.
withFunction
Adds a function for an Object or Interface TypeDef, failing if the type is not one of those kinds.
withInterface
Returns a TypeDef of kind Interface with the provided name.
withKind
Sets the kind of the type.
withListOf
Returns a TypeDef of kind List with the provided type for its elements.
withObject
Returns a TypeDef of kind Object with the provided name.
withOptional
Sets whether this type can be set to null.
withScalar
Returns a TypeDef of kind Scalar with the provided name.

id: ID!

A unique identifier for this TypeDef.

kind: TypeDefKind!

The kind of type this is (e.g. primitive, list, object).

name: String!

The canonical non-optional name of the type.

optional: Boolean!

Whether this type can be set to null. Defaults to false.

asEnum: EnumTypeDef

If kind is ENUM, the enum-specific type definition. If kind is not ENUM, this will be null.

asInput: InputTypeDef

If kind is INPUT, the input-specific type definition. If kind is not INPUT, this will be null.

asInterface: InterfaceTypeDef

If kind is INTERFACE, the interface-specific type definition. If kind is not INTERFACE, this will be null.

asList: ListTypeDef

If kind is LIST, the list-specific type definition. If kind is not LIST, this will be null.

asObject: ObjectTypeDef

If kind is OBJECT, the object-specific type definition. If kind is not OBJECT, this will be null.

asScalar: ScalarTypeDef

If kind is SCALAR, the scalar-specific type definition. If kind is not SCALAR, this will be null.

withConstructor(function: Function!): TypeDef!

Adds a function for constructing a new instance of an Object TypeDef, failing if the type is not an object.

function: Function!

withEnum(name: String!,description: String = "",sourceMap: SourceMap): TypeDef!

Returns a TypeDef of kind Enum with the provided name.

Note that an enum's values may be omitted if the intent is only to refer to an enum. This is how functions are able to return their own, or any other circular reference.

name: String!

The name of the enum

description: String = ""

A doc string for the enum, if any

sourceMap: SourceMap

The source map for the enum definition.

withEnumMember(name: String!,value: String = "",description: String = "",sourceMap: SourceMap,deprecated: String): TypeDef!

Adds a static value for an Enum TypeDef, failing if the type is not an enum.

name: String!

The name of the member in the enum

value: String = ""

The value of the member in the enum

description: String = ""

A doc string for the member, if any

sourceMap: SourceMap

The source map for the enum member definition.

deprecated: String

If deprecated, the reason or migration path.

withEnumValue(value: String!,description: String = "",sourceMap: SourceMap,deprecated: String): TypeDef!Deprecated

Adds a static value for an Enum TypeDef, failing if the type is not an enum.

Deprecated: Use withEnumMember instead

value: String!

The name of the value in the enum

description: String = ""

A doc string for the value, if any

sourceMap: SourceMap

The source map for the enum value definition.

deprecated: String

If deprecated, the reason or migration path.

withField(name: String!,typeDef: TypeDef!,description: String = "",sourceMap: SourceMap,deprecated: String): TypeDef!

Adds a static field for an Object TypeDef, failing if the type is not an object.

name: String!

The name of the field in the object

typeDef: TypeDef!

The type of the field

description: String = ""

A doc string for the field, if any

sourceMap: SourceMap

The source map for the field definition.

deprecated: String

If deprecated, the reason or migration path.

withFunction(function: Function!): TypeDef!

Adds a function for an Object or Interface TypeDef, failing if the type is not one of those kinds.

function: Function!

withInterface(name: String!,description: String = "",sourceMap: SourceMap): TypeDef!

Returns a TypeDef of kind Interface with the provided name.

name: String!
description: String = ""
sourceMap: SourceMap

withKind(kind: TypeDefKind!): TypeDef!

Sets the kind of the type.

kind: TypeDefKind!

withListOf(elementType: TypeDef!): TypeDef!

Returns a TypeDef of kind List with the provided type for its elements.

elementType: TypeDef!

withObject(name: String!,description: String = "",sourceMap: SourceMap,deprecated: String): TypeDef!

Returns a TypeDef of kind Object with the provided name.

Note that an object's fields and functions may be omitted if the intent is only to refer to an object. This is how functions are able to return their own object, or any other circular reference.

name: String!
description: String = ""
sourceMap: SourceMap
deprecated: String

withOptional(optional: Boolean!): TypeDef!

Sets whether this type can be set to null.

optional: Boolean!

withScalar(name: String!, description: String = ""): TypeDef!

Returns a TypeDef of kind Scalar with the provided name.

name: String!
description: String = ""

References

Returned by

Accepted as an argument by