|
8 | 8 | */
|
9 | 9 |
|
10 | 10 | import { forEach, isCollection } from 'iterall';
|
11 |
| - |
12 | 11 | import { GraphQLError, locatedError } from '../error';
|
13 | 12 | import invariant from '../jsutils/invariant';
|
14 | 13 | import isNullish from '../jsutils/isNullish';
|
| 14 | +import type {ObjMap} from '../jsutils/ObjMap'; |
| 15 | + |
15 | 16 | import { typeFromAST } from '../utilities/typeFromAST';
|
16 | 17 | import * as Kind from '../language/kinds';
|
17 | 18 | import {
|
@@ -84,11 +85,11 @@ import type {
|
84 | 85 | */
|
85 | 86 | export type ExecutionContext = {
|
86 | 87 | schema: GraphQLSchema;
|
87 |
| - fragments: {[key: string]: FragmentDefinitionNode}; |
| 88 | + fragments: ObjMap<FragmentDefinitionNode>; |
88 | 89 | rootValue: mixed;
|
89 | 90 | contextValue: mixed;
|
90 | 91 | operation: OperationDefinitionNode;
|
91 |
| - variableValues: {[key: string]: mixed}; |
| 92 | + variableValues: ObjMap<mixed>, |
92 | 93 | fieldResolver: GraphQLFieldResolver<any, any>;
|
93 | 94 | errors: Array<GraphQLError>;
|
94 | 95 | };
|
@@ -278,14 +279,13 @@ export function buildExecutionContext(
|
278 | 279 | document: DocumentNode,
|
279 | 280 | rootValue: mixed,
|
280 | 281 | contextValue: mixed,
|
281 |
| - rawVariableValues: ?{[key: string]: mixed}, |
| 282 | + rawVariableValues: ?ObjMap<mixed>, |
282 | 283 | operationName: ?string,
|
283 | 284 | fieldResolver: ?GraphQLFieldResolver<any, any>
|
284 | 285 | ): ExecutionContext {
|
285 | 286 | const errors: Array<GraphQLError> = [];
|
286 | 287 | let operation: ?OperationDefinitionNode;
|
287 |
| - const fragments: {[name: string]: FragmentDefinitionNode} = |
288 |
| - Object.create(null); |
| 288 | + const fragments: ObjMap<FragmentDefinitionNode> = Object.create(null); |
289 | 289 | document.definitions.forEach(definition => {
|
290 | 290 | switch (definition.kind) {
|
291 | 291 | case Kind.OPERATION_DEFINITION:
|
@@ -340,7 +340,7 @@ function executeOperation(
|
340 | 340 | exeContext: ExecutionContext,
|
341 | 341 | operation: OperationDefinitionNode,
|
342 | 342 | rootValue: mixed
|
343 |
| -): ?{[key: string]: mixed} { |
| 343 | +): ?(Promise<?ObjMap<mixed>> | ObjMap<mixed>) { |
344 | 344 | const type = getOperationRootType(exeContext.schema, operation);
|
345 | 345 | const fields = collectFields(
|
346 | 346 | exeContext,
|
@@ -420,8 +420,8 @@ function executeFieldsSerially(
|
420 | 420 | parentType: GraphQLObjectType,
|
421 | 421 | sourceValue: mixed,
|
422 | 422 | path: ResponsePath,
|
423 |
| - fields: {[key: string]: Array<FieldNode>} |
424 |
| -): Promise<{[key: string]: mixed}> { |
| 423 | + fields: ObjMap<Array<FieldNode>>, |
| 424 | +): Promise<ObjMap<mixed>> { |
425 | 425 | return Object.keys(fields).reduce(
|
426 | 426 | (prevPromise, responseName) => prevPromise.then(results => {
|
427 | 427 | const fieldNodes = fields[responseName];
|
@@ -459,8 +459,8 @@ function executeFields(
|
459 | 459 | parentType: GraphQLObjectType,
|
460 | 460 | sourceValue: mixed,
|
461 | 461 | path: ResponsePath,
|
462 |
| - fields: {[key: string]: Array<FieldNode>} |
463 |
| -): {[key: string]: mixed} { |
| 462 | + fields: ObjMap<Array<FieldNode>>, |
| 463 | +): Promise<ObjMap<mixed>> | ObjMap<mixed> { |
464 | 464 | let containsPromise = false;
|
465 | 465 |
|
466 | 466 | const finalResults = Object.keys(fields).reduce(
|
@@ -510,9 +510,9 @@ export function collectFields(
|
510 | 510 | exeContext: ExecutionContext,
|
511 | 511 | runtimeType: GraphQLObjectType,
|
512 | 512 | selectionSet: SelectionSetNode,
|
513 |
| - fields: {[key: string]: Array<FieldNode>}, |
514 |
| - visitedFragmentNames: {[key: string]: boolean} |
515 |
| -): {[key: string]: Array<FieldNode>} { |
| 513 | + fields: ObjMap<Array<FieldNode>>, |
| 514 | + visitedFragmentNames: ObjMap<boolean>, |
| 515 | +): ObjMap<Array<FieldNode>> { |
516 | 516 | for (let i = 0; i < selectionSet.selections.length; i++) {
|
517 | 517 | const selection = selectionSet.selections[i];
|
518 | 518 | switch (selection.kind) {
|
@@ -621,9 +621,7 @@ function doesFragmentConditionMatch(
|
621 | 621 | * This is akin to bluebird's `Promise.props`, but implemented only using
|
622 | 622 | * `Promise.all` so it will work with any implementation of ES6 promises.
|
623 | 623 | */
|
624 |
| -function promiseForObject<T>( |
625 |
| - object: {[key: string]: Promise<T>} |
626 |
| -): Promise<{[key: string]: T}> { |
| 624 | +function promiseForObject<T>(object: ObjMap<Promise<T>>): Promise<ObjMap<T>> { |
627 | 625 | const keys = Object.keys(object);
|
628 | 626 | const valuesAndPromises = keys.map(name => object[name]);
|
629 | 627 | return Promise.all(valuesAndPromises).then(
|
|
0 commit comments