Skip to content

Prototype of validate step #1083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import type {
InlineFragmentNode,
FragmentDefinitionNode,
} from '../language/ast';
import { assertValidSchema } from '../validation/validateSchema';


/**
Expand Down Expand Up @@ -179,6 +180,8 @@ function executeImpl(
operationName,
fieldResolver
) {
assertValidSchema(schema);

// If arguments are missing or incorrect, throw an error.
assertValidExecutionArguments(
schema,
Expand Down
1 change: 1 addition & 0 deletions src/type/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class GraphQLSchema {
_typeMap: TypeMap;
_implementations: ObjMap<Array<GraphQLObjectType>>;
_possibleTypeMap: ?ObjMap<ObjMap<boolean>>;
__valid: ?boolean;

constructor(config: GraphQLSchemaConfig): void {
invariant(
Expand Down
42 changes: 42 additions & 0 deletions src/validation/validateSchema.js
Original file line number Diff line number Diff line change
@@ -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<GraphQLError> {
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.',
);
}