graphql 0.13.1 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/error/locatedError.js +1 -0
  2. package/error/locatedError.js.flow +1 -0
  3. package/error/locatedError.mjs +1 -0
  4. package/execution/execute.js +26 -36
  5. package/execution/execute.js.flow +33 -43
  6. package/execution/execute.mjs +23 -33
  7. package/execution/values.js.flow +1 -2
  8. package/index.js.flow +1 -0
  9. package/jsutils/MaybePromise.js.flow +1 -1
  10. package/jsutils/isPromise.js +24 -0
  11. package/jsutils/isPromise.js.flow +20 -0
  12. package/jsutils/isPromise.mjs +18 -0
  13. package/jsutils/promiseReduce.js +5 -10
  14. package/jsutils/promiseReduce.js.flow +8 -9
  15. package/jsutils/promiseReduce.mjs +4 -9
  16. package/package.json +2 -2
  17. package/subscription/mapAsyncIterator.js +2 -0
  18. package/subscription/mapAsyncIterator.js.flow +2 -0
  19. package/subscription/mapAsyncIterator.mjs +2 -0
  20. package/type/definition.js +74 -4
  21. package/type/definition.js.flow +80 -1
  22. package/type/definition.mjs +70 -2
  23. package/type/directives.js +3 -3
  24. package/type/directives.js.flow +1 -1
  25. package/type/directives.mjs +8 -8
  26. package/type/index.js +2 -5
  27. package/type/index.js.flow +1 -4
  28. package/type/index.mjs +2 -4
  29. package/type/introspection.js +34 -38
  30. package/type/introspection.js.flow +2 -1
  31. package/type/introspection.mjs +1 -2
  32. package/type/schema.js +7 -5
  33. package/type/schema.js.flow +8 -7
  34. package/type/schema.mjs +7 -5
  35. package/type/validate.js +5 -5
  36. package/type/validate.js.flow +9 -9
  37. package/type/validate.mjs +5 -5
  38. package/utilities/buildASTSchema.js +27 -36
  39. package/utilities/buildASTSchema.js.flow +27 -24
  40. package/utilities/buildASTSchema.mjs +26 -35
  41. package/utilities/buildClientSchema.js +10 -14
  42. package/utilities/buildClientSchema.js.flow +2 -2
  43. package/utilities/buildClientSchema.mjs +1 -3
  44. package/utilities/extendSchema.js +33 -41
  45. package/utilities/extendSchema.js.flow +32 -55
  46. package/utilities/extendSchema.mjs +22 -31
  47. package/utilities/index.js.flow +1 -0
  48. package/utilities/index.mjs +1 -0
  49. package/utilities/isValidLiteralValue.js +6 -2
  50. package/utilities/isValidLiteralValue.js.flow +1 -1
  51. package/utilities/isValidLiteralValue.mjs +1 -1
  52. package/utilities/lexicographicSortSchema.js +2 -4
  53. package/utilities/lexicographicSortSchema.js.flow +2 -1
  54. package/utilities/lexicographicSortSchema.mjs +1 -2
  55. package/utilities/typeFromAST.js +3 -3
  56. package/utilities/typeFromAST.js.flow +1 -1
  57. package/utilities/typeFromAST.mjs +1 -1
  58. package/utilities/valueFromAST.js.flow +5 -13
  59. package/validation/ValidationContext.js +184 -0
  60. package/validation/ValidationContext.js.flow +221 -0
  61. package/validation/ValidationContext.mjs +177 -0
  62. package/validation/index.js +12 -7
  63. package/validation/index.js.flow +5 -1
  64. package/validation/index.mjs +5 -1
  65. package/validation/rules/ExecutableDefinitions.js.flow +1 -1
  66. package/validation/rules/FieldsOnCorrectType.js.flow +1 -1
  67. package/validation/rules/FragmentsOnCompositeTypes.js.flow +1 -1
  68. package/validation/rules/KnownArgumentNames.js.flow +1 -1
  69. package/validation/rules/KnownDirectives.js.flow +1 -1
  70. package/validation/rules/KnownFragmentNames.js.flow +1 -1
  71. package/validation/rules/KnownTypeNames.js.flow +1 -1
  72. package/validation/rules/LoneAnonymousOperation.js.flow +1 -1
  73. package/validation/rules/NoFragmentCycles.js.flow +1 -1
  74. package/validation/rules/NoUndefinedVariables.js.flow +1 -1
  75. package/validation/rules/NoUnusedFragments.js.flow +1 -1
  76. package/validation/rules/NoUnusedVariables.js.flow +1 -1
  77. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +1 -1
  78. package/validation/rules/PossibleFragmentSpreads.js.flow +1 -1
  79. package/validation/rules/ProvidedNonNullArguments.js.flow +1 -1
  80. package/validation/rules/ScalarLeafs.js.flow +1 -1
  81. package/validation/rules/SingleFieldSubscriptions.js.flow +1 -1
  82. package/validation/rules/UniqueArgumentNames.js.flow +1 -1
  83. package/validation/rules/UniqueDirectivesPerLocation.js.flow +1 -1
  84. package/validation/rules/UniqueFragmentNames.js.flow +1 -1
  85. package/validation/rules/UniqueInputFieldNames.js.flow +1 -1
  86. package/validation/rules/UniqueOperationNames.js.flow +1 -1
  87. package/validation/rules/UniqueVariableNames.js.flow +1 -1
  88. package/validation/rules/ValuesOfCorrectType.js.flow +1 -1
  89. package/validation/rules/VariablesAreInputTypes.js.flow +1 -1
  90. package/validation/rules/VariablesDefaultValueAllowed.js.flow +1 -1
  91. package/validation/rules/VariablesInAllowedPosition.js +8 -10
  92. package/validation/rules/VariablesInAllowedPosition.js.flow +2 -3
  93. package/validation/rules/VariablesInAllowedPosition.mjs +1 -2
  94. package/validation/specifiedRules.js.flow +1 -1
  95. package/validation/validate.js +15 -172
  96. package/validation/validate.js.flow +2 -208
  97. package/validation/validate.mjs +2 -164
  98. package/jsutils/getPromise.js +0 -27
  99. package/jsutils/getPromise.js.flow +0 -24
  100. package/jsutils/getPromise.mjs +0 -20
  101. package/type/wrappers.js +0 -89
  102. package/type/wrappers.js.flow +0 -91
  103. package/type/wrappers.mjs +0 -80
@@ -15,6 +15,7 @@ var _GraphQLError = require('./GraphQLError');
15
15
  function locatedError(originalError, nodes, path) {
16
16
  // Note: this uses a brand-check to support GraphQL errors originating from
17
17
  // other contexts.
18
+ // $FlowFixMe(>=0.68.0)
18
19
  if (originalError && Array.isArray(originalError.path)) {
19
20
  return originalError;
20
21
  }
@@ -22,6 +22,7 @@ export function locatedError(
22
22
  ): GraphQLError {
23
23
  // Note: this uses a brand-check to support GraphQL errors originating from
24
24
  // other contexts.
25
+ // $FlowFixMe(>=0.68.0)
25
26
  if (originalError && Array.isArray(originalError.path)) {
26
27
  return (originalError: any);
27
28
  }
@@ -18,6 +18,7 @@ import { GraphQLError } from './GraphQLError';
18
18
  export function locatedError(originalError, nodes, path) {
19
19
  // Note: this uses a brand-check to support GraphQL errors originating from
20
20
  // other contexts.
21
+ // $FlowFixMe(>=0.68.0)
21
22
  if (originalError && Array.isArray(originalError.path)) {
22
23
  return originalError;
23
24
  }
@@ -29,10 +29,6 @@ var _iterall = require('iterall');
29
29
 
30
30
  var _error = require('../error');
31
31
 
32
- var _getPromise = require('../jsutils/getPromise');
33
-
34
- var _getPromise2 = _interopRequireDefault(_getPromise);
35
-
36
32
  var _invariant = require('../jsutils/invariant');
37
33
 
38
34
  var _invariant2 = _interopRequireDefault(_invariant);
@@ -45,6 +41,10 @@ var _isNullish = require('../jsutils/isNullish');
45
41
 
46
42
  var _isNullish2 = _interopRequireDefault(_isNullish);
47
43
 
44
+ var _isPromise = require('../jsutils/isPromise');
45
+
46
+ var _isPromise2 = _interopRequireDefault(_isPromise);
47
+
48
48
  var _memoize = require('../jsutils/memoize3');
49
49
 
50
50
  var _memoize2 = _interopRequireDefault(_memoize);
@@ -160,9 +160,8 @@ function executeImpl(schema, document, rootValue, contextValue, variableValues,
160
160
  * response defined by the "Response" section of the GraphQL specification.
161
161
  */
162
162
  function buildResponse(context, data) {
163
- var promise = (0, _getPromise2.default)(data);
164
- if (promise) {
165
- return promise.then(function (resolved) {
163
+ if ((0, _isPromise2.default)(data)) {
164
+ return data.then(function (resolved) {
166
165
  return buildResponse(context, resolved);
167
166
  });
168
167
  }
@@ -288,9 +287,8 @@ function executeOperation(exeContext, operation, rootValue) {
288
287
  // Similar to completeValueCatchingError.
289
288
  try {
290
289
  var result = operation.operation === 'mutation' ? executeFieldsSerially(exeContext, type, rootValue, path, fields) : executeFields(exeContext, type, rootValue, path, fields);
291
- var promise = (0, _getPromise2.default)(result);
292
- if (promise) {
293
- return promise.then(undefined, function (error) {
290
+ if ((0, _isPromise2.default)(result)) {
291
+ return result.then(undefined, function (error) {
294
292
  exeContext.errors.push(error);
295
293
  return Promise.resolve(null);
296
294
  });
@@ -342,9 +340,8 @@ function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields
342
340
  if (result === undefined) {
343
341
  return results;
344
342
  }
345
- var promise = (0, _getPromise2.default)(result);
346
- if (promise) {
347
- return promise.then(function (resolvedResult) {
343
+ if ((0, _isPromise2.default)(result)) {
344
+ return result.then(function (resolvedResult) {
348
345
  results[responseName] = resolvedResult;
349
346
  return results;
350
347
  });
@@ -369,7 +366,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields) {
369
366
  return results;
370
367
  }
371
368
  results[responseName] = result;
372
- if ((0, _getPromise2.default)(result)) {
369
+ if (!containsPromise && (0, _isPromise2.default)(result)) {
373
370
  containsPromise = true;
374
371
  }
375
372
  return results;
@@ -532,8 +529,7 @@ function resolveFieldValueOrError(exeContext, fieldDef, fieldNodes, resolveFn, s
532
529
  var context = exeContext.contextValue;
533
530
 
534
531
  var result = resolveFn(source, args, context, info);
535
- var promise = (0, _getPromise2.default)(result);
536
- return promise ? promise.then(undefined, asErrorInstance) : result;
532
+ return (0, _isPromise2.default)(result) ? result.then(undefined, asErrorInstance) : result;
537
533
  } catch (error) {
538
534
  return asErrorInstance(error);
539
535
  }
@@ -558,13 +554,12 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
558
554
  // a null value for this field if one is encountered.
559
555
  try {
560
556
  var completed = completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result);
561
- var promise = (0, _getPromise2.default)(completed);
562
- if (promise) {
557
+ if ((0, _isPromise2.default)(completed)) {
563
558
  // If `completeValueWithLocatedError` returned a rejected promise, log
564
559
  // the rejection error and resolve to null.
565
560
  // Note: we don't rely on a `catch` method, but we do expect "thenable"
566
561
  // to take a second callback for the error case.
567
- return promise.then(undefined, function (error) {
562
+ return completed.then(undefined, function (error) {
568
563
  exeContext.errors.push(error);
569
564
  return Promise.resolve(null);
570
565
  });
@@ -583,9 +578,8 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
583
578
  function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result) {
584
579
  try {
585
580
  var completed = completeValue(exeContext, returnType, fieldNodes, info, path, result);
586
- var promise = (0, _getPromise2.default)(completed);
587
- if (promise) {
588
- return promise.then(undefined, function (error) {
581
+ if ((0, _isPromise2.default)(completed)) {
582
+ return completed.then(undefined, function (error) {
589
583
  return Promise.reject((0, _error.locatedError)(asErrorInstance(error), fieldNodes, responsePathAsArray(path)));
590
584
  });
591
585
  }
@@ -618,9 +612,8 @@ function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info,
618
612
  */
619
613
  function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
620
614
  // If result is a Promise, apply-lift over completeValue.
621
- var promise = (0, _getPromise2.default)(result);
622
- if (promise) {
623
- return promise.then(function (resolved) {
615
+ if ((0, _isPromise2.default)(result)) {
616
+ return result.then(function (resolved) {
624
617
  return completeValue(exeContext, returnType, fieldNodes, info, path, resolved);
625
618
  });
626
619
  }
@@ -690,7 +683,7 @@ function completeListValue(exeContext, returnType, fieldNodes, info, path, resul
690
683
  var fieldPath = addPath(path, index);
691
684
  var completedItem = completeValueCatchingError(exeContext, itemType, fieldNodes, info, fieldPath, item);
692
685
 
693
- if (!containsPromise && (0, _getPromise2.default)(completedItem)) {
686
+ if (!containsPromise && (0, _isPromise2.default)(completedItem)) {
694
687
  containsPromise = true;
695
688
  }
696
689
  completedResults.push(completedItem);
@@ -719,9 +712,8 @@ function completeLeafValue(returnType, result) {
719
712
  function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
720
713
  var runtimeType = returnType.resolveType ? returnType.resolveType(result, exeContext.contextValue, info) : defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
721
714
 
722
- var promise = (0, _getPromise2.default)(runtimeType);
723
- if (promise) {
724
- return promise.then(function (resolvedRuntimeType) {
715
+ if ((0, _isPromise2.default)(runtimeType)) {
716
+ return runtimeType.then(function (resolvedRuntimeType) {
725
717
  return completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result);
726
718
  });
727
719
  }
@@ -753,10 +745,9 @@ function completeObjectValue(exeContext, returnType, fieldNodes, info, path, res
753
745
  if (returnType.isTypeOf) {
754
746
  var isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
755
747
 
756
- var promise = (0, _getPromise2.default)(isTypeOf);
757
- if (promise) {
758
- return promise.then(function (isTypeOfResult) {
759
- if (!isTypeOfResult) {
748
+ if ((0, _isPromise2.default)(isTypeOf)) {
749
+ return isTypeOf.then(function (resolvedIsTypeOf) {
750
+ if (!resolvedIsTypeOf) {
760
751
  throw invalidReturnTypeError(returnType, result, fieldNodes);
761
752
  }
762
753
  return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, info, path, result);
@@ -825,9 +816,8 @@ function defaultResolveTypeFn(value, context, info, abstractType) {
825
816
  if (type.isTypeOf) {
826
817
  var isTypeOfResult = type.isTypeOf(value, context, info);
827
818
 
828
- var promise = (0, _getPromise2.default)(isTypeOfResult);
829
- if (promise) {
830
- promisedIsTypeOfResults[i] = promise;
819
+ if ((0, _isPromise2.default)(isTypeOfResult)) {
820
+ promisedIsTypeOfResults[i] = isTypeOfResult;
831
821
  } else if (isTypeOfResult) {
832
822
  return type;
833
823
  }
@@ -9,10 +9,10 @@
9
9
 
10
10
  import { forEach, isCollection } from 'iterall';
11
11
  import { GraphQLError, locatedError } from '../error';
12
- import getPromise from '../jsutils/getPromise';
13
12
  import invariant from '../jsutils/invariant';
14
13
  import isInvalid from '../jsutils/isInvalid';
15
14
  import isNullish from '../jsutils/isNullish';
15
+ import isPromise from '../jsutils/isPromise';
16
16
  import memoize3 from '../jsutils/memoize3';
17
17
  import promiseForObject from '../jsutils/promiseForObject';
18
18
  import promiseReduce from '../jsutils/promiseReduce';
@@ -33,7 +33,6 @@ import {
33
33
  isListType,
34
34
  isNonNullType,
35
35
  } from '../type/definition';
36
- import type { GraphQLList } from '../type/wrappers';
37
36
  import type {
38
37
  GraphQLObjectType,
39
38
  GraphQLOutputType,
@@ -43,6 +42,7 @@ import type {
43
42
  GraphQLFieldResolver,
44
43
  GraphQLResolveInfo,
45
44
  ResponsePath,
45
+ GraphQLList,
46
46
  } from '../type/definition';
47
47
  import { GraphQLSchema } from '../type/schema';
48
48
  import {
@@ -229,9 +229,8 @@ function buildResponse(
229
229
  context: ExecutionContext,
230
230
  data: MaybePromise<ObjMap<mixed> | null>,
231
231
  ) {
232
- const promise = getPromise(data);
233
- if (promise) {
234
- return promise.then(resolved => buildResponse(context, resolved));
232
+ if (isPromise(data)) {
233
+ return data.then(resolved => buildResponse(context, resolved));
235
234
  }
236
235
  return context.errors.length === 0
237
236
  ? { data }
@@ -403,9 +402,8 @@ function executeOperation(
403
402
  operation.operation === 'mutation'
404
403
  ? executeFieldsSerially(exeContext, type, rootValue, path, fields)
405
404
  : executeFields(exeContext, type, rootValue, path, fields);
406
- const promise = getPromise(result);
407
- if (promise) {
408
- return promise.then(undefined, error => {
405
+ if (isPromise(result)) {
406
+ return result.then(undefined, error => {
409
407
  exeContext.errors.push(error);
410
408
  return Promise.resolve(null);
411
409
  });
@@ -484,9 +482,8 @@ function executeFieldsSerially(
484
482
  if (result === undefined) {
485
483
  return results;
486
484
  }
487
- const promise = getPromise(result);
488
- if (promise) {
489
- return promise.then(resolvedResult => {
485
+ if (isPromise(result)) {
486
+ return result.then(resolvedResult => {
490
487
  results[responseName] = resolvedResult;
491
488
  return results;
492
489
  });
@@ -525,7 +522,7 @@ function executeFields(
525
522
  return results;
526
523
  }
527
524
  results[responseName] = result;
528
- if (getPromise(result)) {
525
+ if (!containsPromise && isPromise(result)) {
529
526
  containsPromise = true;
530
527
  }
531
528
  return results;
@@ -684,7 +681,7 @@ function resolveField(
684
681
  source: mixed,
685
682
  fieldNodes: $ReadOnlyArray<FieldNode>,
686
683
  path: ResponsePath,
687
- ): mixed {
684
+ ): MaybePromise<mixed> {
688
685
  const fieldNode = fieldNodes[0];
689
686
  const fieldName = fieldNode.name.value;
690
687
 
@@ -773,8 +770,7 @@ export function resolveFieldValueOrError<TSource>(
773
770
  const context = exeContext.contextValue;
774
771
 
775
772
  const result = resolveFn(source, args, context, info);
776
- const promise = getPromise(result);
777
- return promise ? promise.then(undefined, asErrorInstance) : result;
773
+ return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
778
774
  } catch (error) {
779
775
  return asErrorInstance(error);
780
776
  }
@@ -795,7 +791,7 @@ function completeValueCatchingError(
795
791
  info: GraphQLResolveInfo,
796
792
  path: ResponsePath,
797
793
  result: mixed,
798
- ): mixed {
794
+ ): MaybePromise<mixed> {
799
795
  // If the field type is non-nullable, then it is resolved without any
800
796
  // protection from errors, however it still properly locates the error.
801
797
  if (isNonNullType(returnType)) {
@@ -820,13 +816,12 @@ function completeValueCatchingError(
820
816
  path,
821
817
  result,
822
818
  );
823
- const promise = getPromise(completed);
824
- if (promise) {
819
+ if (isPromise(completed)) {
825
820
  // If `completeValueWithLocatedError` returned a rejected promise, log
826
821
  // the rejection error and resolve to null.
827
822
  // Note: we don't rely on a `catch` method, but we do expect "thenable"
828
823
  // to take a second callback for the error case.
829
- return promise.then(undefined, error => {
824
+ return completed.then(undefined, error => {
830
825
  exeContext.errors.push(error);
831
826
  return Promise.resolve(null);
832
827
  });
@@ -849,7 +844,7 @@ function completeValueWithLocatedError(
849
844
  info: GraphQLResolveInfo,
850
845
  path: ResponsePath,
851
846
  result: mixed,
852
- ): mixed {
847
+ ): MaybePromise<mixed> {
853
848
  try {
854
849
  const completed = completeValue(
855
850
  exeContext,
@@ -859,9 +854,8 @@ function completeValueWithLocatedError(
859
854
  path,
860
855
  result,
861
856
  );
862
- const promise = getPromise(completed);
863
- if (promise) {
864
- return promise.then(undefined, error =>
857
+ if (isPromise(completed)) {
858
+ return completed.then(undefined, error =>
865
859
  Promise.reject(
866
860
  locatedError(
867
861
  asErrorInstance(error),
@@ -909,11 +903,10 @@ function completeValue(
909
903
  info: GraphQLResolveInfo,
910
904
  path: ResponsePath,
911
905
  result: mixed,
912
- ): mixed {
906
+ ): MaybePromise<mixed> {
913
907
  // If result is a Promise, apply-lift over completeValue.
914
- const promise = getPromise(result);
915
- if (promise) {
916
- return promise.then(resolved =>
908
+ if (isPromise(result)) {
909
+ return result.then(resolved =>
917
910
  completeValue(exeContext, returnType, fieldNodes, info, path, resolved),
918
911
  );
919
912
  }
@@ -1012,7 +1005,7 @@ function completeListValue(
1012
1005
  info: GraphQLResolveInfo,
1013
1006
  path: ResponsePath,
1014
1007
  result: mixed,
1015
- ): mixed {
1008
+ ): MaybePromise<$ReadOnlyArray<mixed>> {
1016
1009
  invariant(
1017
1010
  isCollection(result),
1018
1011
  `Expected Iterable, but did not find one for field ${
@@ -1038,7 +1031,7 @@ function completeListValue(
1038
1031
  item,
1039
1032
  );
1040
1033
 
1041
- if (!containsPromise && getPromise(completedItem)) {
1034
+ if (!containsPromise && isPromise(completedItem)) {
1042
1035
  containsPromise = true;
1043
1036
  }
1044
1037
  completedResults.push(completedItem);
@@ -1074,14 +1067,13 @@ function completeAbstractValue(
1074
1067
  info: GraphQLResolveInfo,
1075
1068
  path: ResponsePath,
1076
1069
  result: mixed,
1077
- ): mixed {
1070
+ ): MaybePromise<ObjMap<mixed>> {
1078
1071
  const runtimeType = returnType.resolveType
1079
1072
  ? returnType.resolveType(result, exeContext.contextValue, info)
1080
1073
  : defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
1081
1074
 
1082
- const promise = getPromise(runtimeType);
1083
- if (promise) {
1084
- return promise.then(resolvedRuntimeType =>
1075
+ if (isPromise(runtimeType)) {
1076
+ return runtimeType.then(resolvedRuntimeType =>
1085
1077
  completeObjectValue(
1086
1078
  exeContext,
1087
1079
  ensureValidRuntimeType(
@@ -1103,7 +1095,7 @@ function completeAbstractValue(
1103
1095
  return completeObjectValue(
1104
1096
  exeContext,
1105
1097
  ensureValidRuntimeType(
1106
- ((runtimeType: any): ?GraphQLObjectType | string),
1098
+ runtimeType,
1107
1099
  exeContext,
1108
1100
  returnType,
1109
1101
  fieldNodes,
@@ -1163,17 +1155,16 @@ function completeObjectValue(
1163
1155
  info: GraphQLResolveInfo,
1164
1156
  path: ResponsePath,
1165
1157
  result: mixed,
1166
- ): mixed {
1158
+ ): MaybePromise<ObjMap<mixed>> {
1167
1159
  // If there is an isTypeOf predicate function, call it with the
1168
1160
  // current result. If isTypeOf returns false, then raise an error rather
1169
1161
  // than continuing execution.
1170
1162
  if (returnType.isTypeOf) {
1171
1163
  const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
1172
1164
 
1173
- const promise = getPromise(isTypeOf);
1174
- if (promise) {
1175
- return promise.then(isTypeOfResult => {
1176
- if (!isTypeOfResult) {
1165
+ if (isPromise(isTypeOf)) {
1166
+ return isTypeOf.then(resolvedIsTypeOf => {
1167
+ if (!resolvedIsTypeOf) {
1177
1168
  throw invalidReturnTypeError(returnType, result, fieldNodes);
1178
1169
  }
1179
1170
  return collectAndExecuteSubfields(
@@ -1220,7 +1211,7 @@ function collectAndExecuteSubfields(
1220
1211
  info: GraphQLResolveInfo,
1221
1212
  path: ResponsePath,
1222
1213
  result: mixed,
1223
- ): mixed {
1214
+ ): MaybePromise<ObjMap<mixed>> {
1224
1215
  // Collect sub-fields to execute to complete this value.
1225
1216
  const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
1226
1217
  return executeFields(exeContext, returnType, result, path, subFieldNodes);
@@ -1289,9 +1280,8 @@ function defaultResolveTypeFn(
1289
1280
  if (type.isTypeOf) {
1290
1281
  const isTypeOfResult = type.isTypeOf(value, context, info);
1291
1282
 
1292
- const promise = getPromise(isTypeOfResult);
1293
- if (promise) {
1294
- promisedIsTypeOfResults[i] = promise;
1283
+ if (isPromise(isTypeOfResult)) {
1284
+ promisedIsTypeOfResults[i] = isTypeOfResult;
1295
1285
  } else if (isTypeOfResult) {
1296
1286
  return type;
1297
1287
  }
@@ -11,10 +11,10 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
11
11
 
12
12
  import { forEach, isCollection } from 'iterall';
13
13
  import { GraphQLError, locatedError } from '../error';
14
- import getPromise from '../jsutils/getPromise';
15
14
  import invariant from '../jsutils/invariant';
16
15
  import isInvalid from '../jsutils/isInvalid';
17
16
  import isNullish from '../jsutils/isNullish';
17
+ import isPromise from '../jsutils/isPromise';
18
18
  import memoize3 from '../jsutils/memoize3';
19
19
  import promiseForObject from '../jsutils/promiseForObject';
20
20
  import promiseReduce from '../jsutils/promiseReduce';
@@ -116,9 +116,8 @@ function executeImpl(schema, document, rootValue, contextValue, variableValues,
116
116
  * response defined by the "Response" section of the GraphQL specification.
117
117
  */
118
118
  function buildResponse(context, data) {
119
- var promise = getPromise(data);
120
- if (promise) {
121
- return promise.then(function (resolved) {
119
+ if (isPromise(data)) {
120
+ return data.then(function (resolved) {
122
121
  return buildResponse(context, resolved);
123
122
  });
124
123
  }
@@ -244,9 +243,8 @@ function executeOperation(exeContext, operation, rootValue) {
244
243
  // Similar to completeValueCatchingError.
245
244
  try {
246
245
  var result = operation.operation === 'mutation' ? executeFieldsSerially(exeContext, type, rootValue, path, fields) : executeFields(exeContext, type, rootValue, path, fields);
247
- var promise = getPromise(result);
248
- if (promise) {
249
- return promise.then(undefined, function (error) {
246
+ if (isPromise(result)) {
247
+ return result.then(undefined, function (error) {
250
248
  exeContext.errors.push(error);
251
249
  return Promise.resolve(null);
252
250
  });
@@ -298,9 +296,8 @@ function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields
298
296
  if (result === undefined) {
299
297
  return results;
300
298
  }
301
- var promise = getPromise(result);
302
- if (promise) {
303
- return promise.then(function (resolvedResult) {
299
+ if (isPromise(result)) {
300
+ return result.then(function (resolvedResult) {
304
301
  results[responseName] = resolvedResult;
305
302
  return results;
306
303
  });
@@ -325,7 +322,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields) {
325
322
  return results;
326
323
  }
327
324
  results[responseName] = result;
328
- if (getPromise(result)) {
325
+ if (!containsPromise && isPromise(result)) {
329
326
  containsPromise = true;
330
327
  }
331
328
  return results;
@@ -488,8 +485,7 @@ export function resolveFieldValueOrError(exeContext, fieldDef, fieldNodes, resol
488
485
  var context = exeContext.contextValue;
489
486
 
490
487
  var result = resolveFn(source, args, context, info);
491
- var promise = getPromise(result);
492
- return promise ? promise.then(undefined, asErrorInstance) : result;
488
+ return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
493
489
  } catch (error) {
494
490
  return asErrorInstance(error);
495
491
  }
@@ -514,13 +510,12 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
514
510
  // a null value for this field if one is encountered.
515
511
  try {
516
512
  var completed = completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result);
517
- var promise = getPromise(completed);
518
- if (promise) {
513
+ if (isPromise(completed)) {
519
514
  // If `completeValueWithLocatedError` returned a rejected promise, log
520
515
  // the rejection error and resolve to null.
521
516
  // Note: we don't rely on a `catch` method, but we do expect "thenable"
522
517
  // to take a second callback for the error case.
523
- return promise.then(undefined, function (error) {
518
+ return completed.then(undefined, function (error) {
524
519
  exeContext.errors.push(error);
525
520
  return Promise.resolve(null);
526
521
  });
@@ -539,9 +534,8 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
539
534
  function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result) {
540
535
  try {
541
536
  var completed = completeValue(exeContext, returnType, fieldNodes, info, path, result);
542
- var promise = getPromise(completed);
543
- if (promise) {
544
- return promise.then(undefined, function (error) {
537
+ if (isPromise(completed)) {
538
+ return completed.then(undefined, function (error) {
545
539
  return Promise.reject(locatedError(asErrorInstance(error), fieldNodes, responsePathAsArray(path)));
546
540
  });
547
541
  }
@@ -574,9 +568,8 @@ function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info,
574
568
  */
575
569
  function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
576
570
  // If result is a Promise, apply-lift over completeValue.
577
- var promise = getPromise(result);
578
- if (promise) {
579
- return promise.then(function (resolved) {
571
+ if (isPromise(result)) {
572
+ return result.then(function (resolved) {
580
573
  return completeValue(exeContext, returnType, fieldNodes, info, path, resolved);
581
574
  });
582
575
  }
@@ -646,7 +639,7 @@ function completeListValue(exeContext, returnType, fieldNodes, info, path, resul
646
639
  var fieldPath = addPath(path, index);
647
640
  var completedItem = completeValueCatchingError(exeContext, itemType, fieldNodes, info, fieldPath, item);
648
641
 
649
- if (!containsPromise && getPromise(completedItem)) {
642
+ if (!containsPromise && isPromise(completedItem)) {
650
643
  containsPromise = true;
651
644
  }
652
645
  completedResults.push(completedItem);
@@ -675,9 +668,8 @@ function completeLeafValue(returnType, result) {
675
668
  function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
676
669
  var runtimeType = returnType.resolveType ? returnType.resolveType(result, exeContext.contextValue, info) : defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
677
670
 
678
- var promise = getPromise(runtimeType);
679
- if (promise) {
680
- return promise.then(function (resolvedRuntimeType) {
671
+ if (isPromise(runtimeType)) {
672
+ return runtimeType.then(function (resolvedRuntimeType) {
681
673
  return completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result);
682
674
  });
683
675
  }
@@ -709,10 +701,9 @@ function completeObjectValue(exeContext, returnType, fieldNodes, info, path, res
709
701
  if (returnType.isTypeOf) {
710
702
  var isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
711
703
 
712
- var promise = getPromise(isTypeOf);
713
- if (promise) {
714
- return promise.then(function (isTypeOfResult) {
715
- if (!isTypeOfResult) {
704
+ if (isPromise(isTypeOf)) {
705
+ return isTypeOf.then(function (resolvedIsTypeOf) {
706
+ if (!resolvedIsTypeOf) {
716
707
  throw invalidReturnTypeError(returnType, result, fieldNodes);
717
708
  }
718
709
  return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, info, path, result);
@@ -781,9 +772,8 @@ function defaultResolveTypeFn(value, context, info, abstractType) {
781
772
  if (type.isTypeOf) {
782
773
  var isTypeOfResult = type.isTypeOf(value, context, info);
783
774
 
784
- var promise = getPromise(isTypeOfResult);
785
- if (promise) {
786
- promisedIsTypeOfResults[i] = promise;
775
+ if (isPromise(isTypeOfResult)) {
776
+ promisedIsTypeOfResults[i] = isTypeOfResult;
787
777
  } else if (isTypeOfResult) {
788
778
  return type;
789
779
  }
@@ -24,7 +24,6 @@ import type { GraphQLSchema } from '../type/schema';
24
24
  import type {
25
25
  FieldNode,
26
26
  DirectiveNode,
27
- VariableNode,
28
27
  VariableDefinitionNode,
29
28
  } from '../language/ast';
30
29
 
@@ -139,7 +138,7 @@ export function getArgumentValues(
139
138
  );
140
139
  }
141
140
  } else if (argumentNode.value.kind === Kind.VARIABLE) {
142
- const variableName = (argumentNode.value: VariableNode).name.value;
141
+ const variableName = argumentNode.value.name.value;
143
142
  if (
144
143
  variableValues &&
145
144
  Object.prototype.hasOwnProperty.call(variableValues, variableName) &&
package/index.js.flow CHANGED
@@ -375,6 +375,7 @@ export {
375
375
  } from './utilities';
376
376
 
377
377
  export type {
378
+ BuildSchemaOptions,
378
379
  BreakingChange,
379
380
  DangerousChange,
380
381
  IntrospectionOptions,
@@ -7,4 +7,4 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- export type MaybePromise<T> = Promise<T> | T;
10
+ export type MaybePromise<+T> = Promise<T> | T;
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isPromise;
7
+
8
+
9
+ // eslint-disable-next-line no-redeclare
10
+ function isPromise(value) {
11
+ return Boolean(value && typeof value.then === 'function');
12
+ } /**
13
+ * Copyright (c) 2015-present, Facebook, Inc.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ * strict
19
+ */
20
+
21
+ /**
22
+ * Returns true if the value acts like a Promise, i.e. has a "then" function,
23
+ * otherwise returns false.
24
+ */
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ /**
11
+ * Returns true if the value acts like a Promise, i.e. has a "then" function,
12
+ * otherwise returns false.
13
+ */
14
+ declare function isPromise(value: mixed): boolean %checks(value instanceof
15
+ Promise);
16
+
17
+ // eslint-disable-next-line no-redeclare
18
+ export default function isPromise(value) {
19
+ return Boolean(value && typeof value.then === 'function');
20
+ }