( schema: GraphQLSchema, )
| 92 | * ``` |
| 93 | */ |
| 94 | export function validateSchema( |
| 95 | schema: GraphQLSchema, |
| 96 | ): ReadonlyArray<GraphQLError> { |
| 97 | // First check to ensure the provided value is in fact a GraphQLSchema. |
| 98 | assertSchema(schema); |
| 99 | |
| 100 | // If this Schema has already been validated, return the previous results. |
| 101 | if (schema.__validationErrors) { |
| 102 | return schema.__validationErrors; |
| 103 | } |
| 104 | |
| 105 | // Validate the schema, producing a list of errors. |
| 106 | const context = new SchemaValidationContext(schema); |
| 107 | validateRootTypes(context); |
| 108 | validateDirectives(context); |
| 109 | validateTypes(context); |
| 110 | |
| 111 | // Persist the results of validation before returning to ensure validation |
| 112 | // does not run multiple times for this schema. |
| 113 | const errors = context.getErrors(); |
| 114 | schema.__validationErrors = errors; |
| 115 | return errors; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Utility function which asserts a schema is valid by throwing an error if |
no test coverage detected