SchemaBuilder
SchemaBuilder is the core class of Pothos. It can be used to build types, and merge them into a graphql.js Schema.
constructor<SchemaTypes>(options)
- typeParam:
SchemaTypes: A type that describes the backing models for your schema - options:
SchemaBuilderOptions
SchemaTypes
SchemaBuilderOptions
By default there are no options for SchemaBuilder, but plugins may contribute additional options
queryType(options, fields?)
creates the Query with a set of Query fields
options:QueryTypeOptionsfields?: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
QueryTypeOptions
description: A description of the current typefields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
queryFields(fields)
add a set of fields to the Query type.
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
queryField(name, field)
add a single field to the Query type.
name: the name of the fieldfield: a function that receives aFieldBuilder, and returns field ref. SeeFieldBuilderfor more details.
mutationType(options, fields?)
creates the Mutation with a set of Mutation fields
options:MutationTypeOptionsfields?: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
MutationTypeOptions
description: A description of the current typefields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
mutationFields(fields)
add a set of fields to the Mutation type.
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
mutationField(name, field)
add a single field to the Mutation type.
name: the name of the fieldfield: a function that receives aFieldBuilder, and returns field ref. SeeFieldBuilderfor more details.
subscriptionType(options, fields?)
creates the Subscription with a set of Subscription fields
options:SubscriptionTypeOptionsfields?: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
SubscriptionTypeOptions
description: A description of the current typefields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
subscriptionFields(fields)
add a set of fields to the Subscription type.
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
subscriptionField(name, field)
add a single field to the Subscription type.
name: the name of the fieldfield: a function that receives aFieldBuilder, and returns field ref. SeeFieldBuilderfor more details.
objectType(param, options, fields?)
-
param: A key of theObjectsproperty inSchemaTypes, a class, or a TypeRef created bybuilder.objectRef -
options:ObjectTypeOptions -
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
ObjectTypeOptions
-
description: A description of the current type -
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details. -
isTypeOf: Recomended when implementing interfaces. This is a method that will be used when determining if a value of an implemented interface is of the current type. -
interfaces: an array of interfaces implemented by this interface type. Items in this array should be an interface param. Seeparamargument ofinterfaceType -
name: name of GraphQL type. Required when param is a class
objectFields(param, fields)
add a set of fields to the object type.
-
param: A key of theObjectsproperty inSchemaTypes, a class, or a TypeRef created bybuilder.objectRef -
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
objectField(param, name, field)
add a single field to the object type.
-
name: the name of the field -
param: A key of theObjectsproperty inSchemaTypes, a class, or a TypeRef created bybuilder.objectRef -
field: a function that receives aFieldBuilder, and returns field ref. SeeFieldBuilderfor more details.
objectRef<T>(name)
Creates a Ref object represent an object that has not been implemented. This can be useful for building certain types of plugins, or when building a modular schema where you don't want to define all types in SchemaTypes, or import the actual implementation of each object type you use.
name: string, name of the type that this ref represents. Can be overwritten when implemented.T: a type param to define the backing shape for the type that this ref represents
interfaceType(param, options, fields?)
-
param: A key of theInterfacesproperty inSchemaTypes, a class, or a TypeRef created bybuilder.interfaceRef -
options:InterfaceTypeOptions -
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
InterfaceTypeOptions
-
description: A description of the current type -
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details. -
interfaces: an array of interfaces implemented by this interface type. Items in this array should be an interface param. Seeparamargument ofinterfaceType -
name: name of GraphQL type. Required when param is a class
interfaceFields(param, fields)
add a set of fields to the interface type.
-
param: A key of theInterfacesproperty inSchemaTypes, a class, or a TypeRef created bybuilder.interfaceRef -
fields: a function that receives aFieldBuilder, and returns an object of field names to field refs. SeeFieldBuilderfor more details.
interfaceField(paran, name, field)
add a single field to the interface type.
-
param: A key of theInterfacesproperty inSchemaTypes, a class, or a TypeRef created bybuilder.interfaceRef -
name: the name of the field -
field: a function that receives aFieldBuilder, and returns field ref. SeeFieldBuilderfor more details.
interfaceRef<T>(name)
Creates a Ref object represent an interface that has not been implemented. This can be useful for building certain types of plugins, or when building a modular schema where you don't want to define all types in SchemaTypes, or import the actual implementation of each interface type you use.
name: string, name of the type that this ref represents. Can be overwritten when implemented.T: a type param to define the backing shape for the type that this ref represents
unionType(name, options)
name: A stringoptions:UnionTypeOptions
UnionTypeOptions
-
description: A description of the current type -
types: an array of object types included in the union type. Items in this array should be Object params. Seeparamargument inbuilder.objectType. -
resolveType: A function called when resolving the type of a union value.parentwill be a union of the backing models of the types provided intypes. This function should return the name of one of the union member types.
enumType(param, options)
param: A string name of the enum or a typescript enumoptions:EnumTypeOptions
EnumTypeOptions
-
description: A description of the current type -
values: can be either an array of strings (you may need to useas constto get proper type names) or aGraphQLEnumValueConfigMap. values is only required when param is not an enum -
name: required when param is an enum
addScalarType(name, scalar, options)
name: A key of theInterfaceproperty inSchemaTypesscalar: AGraphQLScalar
scalarType(name, options)
name: A key of theInterfaceproperty inSchemaTypesoptions:ScalarTypeOptions
ScalarTypeOptions
inputType(param, options)
param: a string or InputRef created bybuilder.inputRefoptions:InputTypeOptions
InputTypeOptions
description: A description of the current typefields: a function that receives anInputFieldBuilder, and returns an object of field names to field definitions. SeeInputFieldBuilderfor more details. Ifnameis a key of theInputproperty inSchemaTypes, shape will show type errors for any fields that do not match the types provided inSchemaTypes.
inputRef<T>(name)
Creates a Ref object represent an input object that has not been implemented. This can be useful for defining recursive input types, for building certain types of plugins, or when building a modular schema where you don't want to define all types in SchemaTypes, or import the actual implementation of each input type you use.
name: string, name of the type that this ref represents. Can be overwritten when implemented.T: a type param to define the backing shape for the type that this ref represents
args(fields)
Creates an arguments object which can be used as the args option in a field definition.
fields: a function that receives anArgBuilder, and returns an object of field names to field definitions. SeeArgBuilderfor more details.
toSchema(types)
Takes an array of types created by SchemaBuilder and returns a
GraphQLSchema
SchemaBuilder.allowPluginReRegistration
SchemaBuilder.allowPluginReRegistration is a static boolean on the SchemaBuilder class that can
be set to allow plugins to call registerPlugin multiple times. This is useful for hot-module
reloading, but is false by default to catch any issues with duplicate versions of a plugin.