Skip to content
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

Throw an error on asynchronous introspection query behavior. #1955

Merged
merged 1 commit into from
Nov 13, 2018
Merged
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
12 changes: 12 additions & 0 deletions packages/apollo-server-core/src/utils/schemaHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ import stableStringify from 'json-stable-stringify';
import { GraphQLSchema } from 'graphql/type';
import { createHash } from 'crypto';

const hasOwn = Object.prototype.hasOwnProperty;

export function generateSchemaHash(schema: GraphQLSchema): string {
const introspectionQuery = getIntrospectionQuery();
const documentAST = parse(introspectionQuery);
const result = execute(schema, documentAST) as ExecutionResult;

// If the execution of an introspection query results in a then-able, it
// indicates that one or more of its resolvers is behaving in an asynchronous
// manner. This is not the expected behavior of a introspection query
// which does not have any asynchronous resolvers.
if (hasOwn.call(result, 'then')) {
throw new Error(
'The introspection query is resolving asynchronously; execution of an introspection query is not expected to return a `Promise`.',
);
}

if (!result || !result.data || !result.data.__schema) {
throw new Error('Unable to generate server introspection document.');
}
Expand Down