Skip to content

Commit

Permalink
Follow up on #1955's incorrect then-able check.
Browse files Browse the repository at this point in the history
I foolishly used `O.p.hasOwnProperty` here which, while safe for checking
properties, is actually not correct since this `then` property is inherited
from `Promise.prototype.then`.

Checking if `then` is a function should be safe _enough_.

Follows-up on: #1955
  • Loading branch information
abernix committed Nov 13, 2018
1 parent c82cdec commit e90e955
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions packages/apollo-server-core/src/utils/schemaHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ 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);
Expand All @@ -16,7 +14,7 @@ export function generateSchemaHash(schema: GraphQLSchema): string {
// 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')) {
if (result && typeof result.then === 'function') {
throw new Error(
'The introspection query is resolving asynchronously; execution of an introspection query is not expected to return a `Promise`.',
);
Expand Down

0 comments on commit e90e955

Please sign in to comment.