validateSchema function

List<GraphQLError> validateSchema(
  1. GraphQLSchema schema
)

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.

Implementation

List<GraphQLError> validateSchema(
  GraphQLSchema schema,
) {
  // If this Schema has already been validated, return the previous results.
  if (schema.__validationErrors != null) {
    return schema.__validationErrors!;
  }

  // Validate the schema, producing a list of errors.
  final context = SchemaValidationContext(schema);
  validateRootTypes(context);
  validateDirectives(context);
  validateTypes(context);
  validateAttachments(context);

  // Persist the results of validation before returning to ensure validation
  // does not run multiple times for this schema.
  final errors = context.getErrors();
  schema.__validationErrors = errors;
  return errors;
}