graphql/type/validation
Functions
validateSchema()
Implements the “Type Validation” sub-sections of the specification’s “Type System” section.
Validation runs synchronously, returning an array of encountered errors, or an empty array if no errors were encountered and the Schema is valid.
Signature:
validateSchema(schema: GraphQLSchema): readonly GraphQLError[]
Arguments
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
Returns
| Type | Description |
|---|---|
readonly GraphQLError[] | Schema validation errors, or an empty array when the schema is valid. |
Example
import { GraphQLObjectType, GraphQLSchema, GraphQLString, validateSchema } from 'graphql/type';
const schema = new GraphQLSchema({
query: new GraphQLObjectType({ name: 'Query', fields: { name: { type: GraphQLString } } }),
});
const errors = validateSchema(schema);
// errors.length: 0assertValidSchema()
Utility function which asserts a schema is valid by throwing an error if it is invalid.
Signature:
assertValidSchema(schema: GraphQLSchema): void
Arguments
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
Example
import { GraphQLObjectType, GraphQLSchema, GraphQLString, assertValidSchema } from 'graphql/type';
const schema = new GraphQLSchema({
query: new GraphQLObjectType({ name: 'Query', fields: { name: { type: GraphQLString } } }),
});
assertValidSchema(schema);
// does not throw for a valid schema