Class: TypeDef
A definition of a parameter or return type in a Module.
Extends
BaseClient
Constructors
new TypeDef()
new TypeDef(
ctx
?,_id
?,_kind
?,_optional
?):TypeDef
Constructor is used for internal usage only, do not create object from it.
Parameters
ctx?
Context
_id?
_kind?
_optional?
boolean
Returns
Overrides
BaseClient.constructor
Methods
asEnum()
asEnum():
EnumTypeDef
If kind is ENUM, the enum-specific type definition. If kind is not ENUM, this will be null.
Returns
asInput()
asInput():
InputTypeDef
If kind is INPUT, the input-specific type definition. If kind is not INPUT, this will be null.
Returns
asInterface()
asInterface():
InterfaceTypeDef
If kind is INTERFACE, the interface-specific type definition. If kind is not INTERFACE, this will be null.
Returns
asList()
asList():
ListTypeDef
If kind is LIST, the list-specific type definition. If kind is not LIST, this will be null.
Returns
asObject()
asObject():
ObjectTypeDef
If kind is OBJECT, the object-specific type definition. If kind is not OBJECT, this will be null.
Returns
asScalar()
asScalar():
ScalarTypeDef
If kind is SCALAR, the scalar-specific type definition. If kind is not SCALAR, this will be null.
Returns
id()
id():
Promise
<TypeDefID
>
A unique identifier for this TypeDef.
Returns
Promise
<TypeDefID
>
kind()
kind():
Promise
<TypeDefKind
>
The kind of type this is (e.g. primitive, list, object).
Returns
Promise
<TypeDefKind
>
optional()
optional():
Promise
<boolean
>
Whether this type can be set to null. Defaults to false.
Returns
Promise
<boolean
>
with()
with(
arg
):TypeDef
Call the provided function with current TypeDef.
This is useful for reusability and readability by not breaking the calling chain.
Parameters
arg
(param
) => TypeDef
Returns
withConstructor()
withConstructor(
function_
):TypeDef
Adds a function for constructing a new instance of an Object TypeDef, failing if the type is not an object.
Parameters
function_
Returns
withEnum()
withEnum(
name
,opts
?):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.
Parameters
name
string
The name of the enum
opts?
Returns
withEnumValue()
withEnumValue(
value
,opts
?):TypeDef
Adds a static value for an Enum TypeDef, failing if the type is not an enum.
Parameters
value
string
The name of the value in the enum
opts?
Returns
withField()
withField(
name
,typeDef
,opts
?):TypeDef
Adds a static field for an Object TypeDef, failing if the type is not an object.
Parameters
name
string
The name of the field in the object
typeDef
The type of the field
opts?
Returns
withFunction()
withFunction(
function_
):TypeDef
Adds a function for an Object or Interface TypeDef, failing if the type is not one of those kinds.
Parameters
function_
Returns
withInterface()
withInterface(
name
,opts
?):TypeDef
Returns a TypeDef of kind Interface with the provided name.
Parameters
name
string
opts?
Returns
withKind()
withKind(
kind
):TypeDef
Sets the kind of the type.
Parameters
kind
Returns
withListOf()
withListOf(
elementType
):TypeDef
Returns a TypeDef of kind List with the provided type for its elements.
Parameters
elementType
Returns
withObject()
withObject(
name
,opts
?):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.
Parameters
name
string
opts?
Returns
withOptional()
withOptional(
optional
):TypeDef
Sets whether this type can be set to null.
Parameters
optional
boolean
Returns
withScalar()
withScalar(
name
,opts
?):TypeDef
Returns a TypeDef of kind Scalar with the provided name.
Parameters
name
string