diff --git a/src/execution/execute.js b/src/execution/execute.js index bd5cd06263..7c7d15db30 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -55,6 +55,7 @@ import type { InlineFragmentNode, FragmentDefinitionNode, } from '../language/ast'; +import { assertValidSchema } from '../validation/validateSchema'; /** @@ -179,6 +180,8 @@ function executeImpl( operationName, fieldResolver ) { + assertValidSchema(schema); + // If arguments are missing or incorrect, throw an error. assertValidExecutionArguments( schema, diff --git a/src/type/schema.js b/src/type/schema.js index ad1208c0d5..8a9d51350e 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -64,6 +64,7 @@ export class GraphQLSchema { _typeMap: TypeMap; _implementations: ObjMap>; _possibleTypeMap: ?ObjMap>; + __valid: ?boolean; constructor(config: GraphQLSchemaConfig): void { invariant( diff --git a/src/validation/validateSchema.js b/src/validation/validateSchema.js new file mode 100644 index 0000000000..0df506b81e --- /dev/null +++ b/src/validation/validateSchema.js @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import invariant from '../jsutils/invariant'; + +import type { GraphQLSchema } from '../type/schema'; +import type { GraphQLError } from '../error'; + +/** + * Validation runs synchronously, returning an array of encountered errors, or + * an empty array if no errors were encountered and the document is valid. + */ +export function validateSchema( + schema: GraphQLSchema, +): Array { + if (schema.__valid === true) { + return []; + } + const errors = []; + + // TODO actually validate the schema + + if (errors.length === 0) { + schema.__valid = true; + } + return errors; +} + +export function assertValidSchema( + schema: GraphQLSchema, +): void { + console.error( + 'The schema has to be validated by calling `validateSchema()` before ' + + 'usage.', + ); +}