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

Rename 'MaybePromise' to 'PromiseOrValue' #1798

Merged
merged 1 commit into from
Mar 22, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import memoize3 from '../jsutils/memoize3';
import promiseForObject from '../jsutils/promiseForObject';
import promiseReduce from '../jsutils/promiseReduce';
import type { ObjMap } from '../jsutils/ObjMap';
import type { MaybePromise } from '../jsutils/MaybePromise';
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';

import { getOperationRootType } from '../utilities/getOperationRootType';
import { typeFromAST } from '../utilities/typeFromAST';
Expand Down Expand Up @@ -144,7 +144,7 @@ export type ExecutionArgs = {|
declare function execute(
ExecutionArgs,
..._: []
): MaybePromise<ExecutionResult>;
): PromiseOrValue<ExecutionResult>;
/* eslint-disable no-redeclare */
declare function execute(
schema: GraphQLSchema,
Expand All @@ -155,7 +155,7 @@ declare function execute(
operationName?: ?string,
fieldResolver?: ?GraphQLFieldResolver<any, any>,
typeResolver?: ?GraphQLTypeResolver<any, any>,
): MaybePromise<ExecutionResult>;
): PromiseOrValue<ExecutionResult>;
export function execute(
argsOrSchema,
document,
Expand Down Expand Up @@ -239,7 +239,7 @@ function executeImpl(
*/
function buildResponse(
exeContext: ExecutionContext,
data: MaybePromise<ObjMap<mixed> | null>,
data: PromiseOrValue<ObjMap<mixed> | null>,
) {
if (isPromise(data)) {
return data.then(resolved => buildResponse(exeContext, resolved));
Expand Down Expand Up @@ -393,7 +393,7 @@ function executeOperation(
exeContext: ExecutionContext,
operation: OperationDefinitionNode,
rootValue: mixed,
): MaybePromise<ObjMap<mixed> | null> {
): PromiseOrValue<ObjMap<mixed> | null> {
const type = getOperationRootType(exeContext.schema, operation);
const fields = collectFields(
exeContext,
Expand Down Expand Up @@ -438,7 +438,7 @@ function executeFieldsSerially(
sourceValue: mixed,
path: ResponsePath | void,
fields: ObjMap<Array<FieldNode>>,
): MaybePromise<ObjMap<mixed>> {
): PromiseOrValue<ObjMap<mixed>> {
return promiseReduce(
Object.keys(fields),
(results, responseName) => {
Expand Down Expand Up @@ -477,7 +477,7 @@ function executeFields(
sourceValue: mixed,
path: ResponsePath | void,
fields: ObjMap<Array<FieldNode>>,
): MaybePromise<ObjMap<mixed>> {
): PromiseOrValue<ObjMap<mixed>> {
const results = Object.create(null);
let containsPromise = false;

Expand Down Expand Up @@ -653,7 +653,7 @@ function resolveField(
source: mixed,
fieldNodes: $ReadOnlyArray<FieldNode>,
path: ResponsePath,
): MaybePromise<mixed> {
): PromiseOrValue<mixed> {
const fieldNode = fieldNodes[0];
const fieldName = fieldNode.name.value;

Expand Down Expand Up @@ -766,7 +766,7 @@ function completeValueCatchingError(
info: GraphQLResolveInfo,
path: ResponsePath,
result: mixed,
): MaybePromise<mixed> {
): PromiseOrValue<mixed> {
try {
let completed;
if (isPromise(result)) {
Expand Down Expand Up @@ -844,7 +844,7 @@ function completeValue(
info: GraphQLResolveInfo,
path: ResponsePath,
result: mixed,
): MaybePromise<mixed> {
): PromiseOrValue<mixed> {
// If result is an Error, throw a located error.
if (result instanceof Error) {
throw result;
Expand Down Expand Up @@ -939,7 +939,7 @@ function completeListValue(
info: GraphQLResolveInfo,
path: ResponsePath,
result: mixed,
): MaybePromise<$ReadOnlyArray<mixed>> {
): PromiseOrValue<$ReadOnlyArray<mixed>> {
invariant(
isCollection(result),
`Expected Iterable, but did not find one for field ${
Expand Down Expand Up @@ -1001,7 +1001,7 @@ function completeAbstractValue(
info: GraphQLResolveInfo,
path: ResponsePath,
result: mixed,
): MaybePromise<ObjMap<mixed>> {
): PromiseOrValue<ObjMap<mixed>> {
const resolveTypeFn = returnType.resolveType || exeContext.typeResolver;
const contextValue = exeContext.contextValue;
const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
Expand Down Expand Up @@ -1088,7 +1088,7 @@ function completeObjectValue(
info: GraphQLResolveInfo,
path: ResponsePath,
result: mixed,
): MaybePromise<ObjMap<mixed>> {
): PromiseOrValue<ObjMap<mixed>> {
// If there is an isTypeOf predicate function, call it with the
// current result. If isTypeOf returns false, then raise an error rather
// than continuing execution.
Expand Down Expand Up @@ -1141,7 +1141,7 @@ function collectAndExecuteSubfields(
fieldNodes: $ReadOnlyArray<FieldNode>,
path: ResponsePath,
result: mixed,
): MaybePromise<ObjMap<mixed>> {
): PromiseOrValue<ObjMap<mixed>> {
// Collect sub-fields to execute to complete this value.
const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
return executeFields(exeContext, returnType, result, path, subFieldNodes);
Expand Down
4 changes: 2 additions & 2 deletions src/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
} from './type/definition';
import type { GraphQLSchema } from './type/schema';
import type { ExecutionResult } from './execution/execute';
import type { MaybePromise } from './jsutils/MaybePromise';
import type { PromiseOrValue } from './jsutils/PromiseOrValue';

/**
* This is the primary entry point function for fulfilling GraphQL operations
Expand Down Expand Up @@ -188,7 +188,7 @@ function graphqlImpl(
operationName,
fieldResolver,
typeResolver,
): MaybePromise<ExecutionResult> {
): PromiseOrValue<ExecutionResult> {
// Validate Schema
const schemaValidationErrors = validateSchema(schema);
if (schemaValidationErrors.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* @flow strict
*/

export type MaybePromise<+T> = Promise<T> | T;
export type PromiseOrValue<+T> = Promise<T> | T;
8 changes: 4 additions & 4 deletions src/jsutils/promiseReduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import isPromise from './isPromise';
import type { MaybePromise } from './MaybePromise';
import type { PromiseOrValue } from './PromiseOrValue';

/**
* Similar to Array.prototype.reduce(), however the reducing callback may return
Expand All @@ -19,9 +19,9 @@ import type { MaybePromise } from './MaybePromise';
*/
export default function promiseReduce<T, U>(
values: $ReadOnlyArray<T>,
callback: (U, T) => MaybePromise<U>,
initialValue: MaybePromise<U>,
): MaybePromise<U> {
callback: (U, T) => PromiseOrValue<U>,
initialValue: PromiseOrValue<U>,
): PromiseOrValue<U> {
return values.reduce(
(previous, value) =>
isPromise(previous)
Expand Down
8 changes: 4 additions & 4 deletions src/subscription/mapAsyncIterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
*/

import { $$asyncIterator, getAsyncIterator } from 'iterall';
import type { MaybePromise } from '../jsutils/MaybePromise';
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';

/**
* Given an AsyncIterable and a callback function, return an AsyncIterator
* which produces values mapped via calling the callback function.
*/
export default function mapAsyncIterator<T, U>(
iterable: AsyncIterable<T>,
callback: T => MaybePromise<U>,
rejectCallback?: any => MaybePromise<U>,
callback: T => PromiseOrValue<U>,
rejectCallback?: any => PromiseOrValue<U>,
): AsyncGenerator<U, void, void> {
const iterator = getAsyncIterator(iterable);
let $return;
Expand Down Expand Up @@ -71,7 +71,7 @@ export default function mapAsyncIterator<T, U>(

function asyncMapValue<T, U>(
value: T,
callback: T => MaybePromise<U>,
callback: T => PromiseOrValue<U>,
): Promise<U> {
return new Promise(resolve => resolve(callback(value)));
}
Expand Down
6 changes: 3 additions & 3 deletions src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import type {
ValueNode,
} from '../language/ast';
import type { GraphQLSchema } from './schema';
import type { MaybePromise } from '../jsutils/MaybePromise';
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';

// Predicates & Assertions

Expand Down Expand Up @@ -839,13 +839,13 @@ export type GraphQLTypeResolver<TSource, TContext> = (
context: TContext,
info: GraphQLResolveInfo,
abstractType: GraphQLAbstractType,
) => MaybePromise<?GraphQLObjectType | string>;
) => PromiseOrValue<?GraphQLObjectType | string>;

export type GraphQLIsTypeOfFn<TSource, TContext> = (
source: TSource,
context: TContext,
info: GraphQLResolveInfo,
) => MaybePromise<boolean>;
) => PromiseOrValue<boolean>;

export type GraphQLFieldResolver<
TSource,
Expand Down