Skip to content

Commit

Permalink
Reduce scope
Browse files Browse the repository at this point in the history
Just reverts a few unrelated parts of the change
  • Loading branch information
leebyron authored Jan 20, 2017
1 parent ae5295a commit 1305360
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,30 +941,24 @@ function completeAbstractValue(
result: mixed
): mixed {
const runtimeType = returnType.resolveType ?
returnType.resolveType(
result,
exeContext.contextValue,
info
) :
defaultResolveTypeFn(
result,
exeContext.contextValue,
info,
returnType
);
returnType.resolveType(result, exeContext.contextValue, info) :
defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);

if (isThenable(runtimeType)) {
return ((runtimeType: any): Promise<*>).then(resolvedRuntimeType => (
// Cast to Promise
const runtimeTypePromise: Promise<GraphQLObjectType | string> =
(runtimeType: any);
return runtimeTypePromise.then(resolvedRuntimeType =>
validateRuntimeTypeAndCompleteObjectValue(
exeContext,
returnType,
fieldNodes,
info,
path,
resolvedRuntimeType,
ensureType(exeContext.schema, resolvedRuntimeType),
result
)
));
);
}

return validateRuntimeTypeAndCompleteObjectValue(
Expand All @@ -973,27 +967,29 @@ function completeAbstractValue(
fieldNodes,
info,
path,
runtimeType,
ensureType(exeContext.schema, runtimeType),
result
);
}

function ensureType(
schema: GraphQLSchema,
typeOrName: string | GraphQLObjectType
): GraphQLObjectType {
return typeof typeOrName === 'string' ?
schema.getType(typeOrName) :
typeOrName;
}

function validateRuntimeTypeAndCompleteObjectValue(
exeContext: ExecutionContext,
returnType: GraphQLAbstractType,
fieldNodes: Array<FieldNode>,
info: GraphQLResolveInfo,
path: ResponsePath,
returnedRuntimeType: mixed,
runtimeType: GraphQLObjectType,
result: mixed
): mixed {
let runtimeType = returnedRuntimeType;

// If resolveType returns a string, we assume it's a GraphQLObjectType name.
if (typeof runtimeType === 'string') {
runtimeType = exeContext.schema.getType(runtimeType);
}

if (!(runtimeType instanceof GraphQLObjectType)) {
throw new GraphQLError(
`Abstract type ${returnType.name} must resolve to an Object type at ` +
Expand Down Expand Up @@ -1087,16 +1083,14 @@ function validateResultTypeAndExecuteFields(
// rather than continuing execution.
if (!isTypeOfResult) {
throw new GraphQLError(
`Expected value of type "${returnType.name}" ` +
`but got: ${String(result)}.`,
`Expected value of type "${returnType.name}" but got: ${String(result)}.`,
fieldNodes
);
}

// Collect sub-fields to execute to complete this value.
let subFieldNodes = Object.create(null);
const visitedFragmentNames = Object.create(null);

for (let i = 0; i < fieldNodes.length; i++) {
const selectionSet = fieldNodes[i].selectionSet;
if (selectionSet) {
Expand All @@ -1122,7 +1116,7 @@ function defaultResolveTypeFn(
value: mixed,
context: mixed,
info: GraphQLResolveInfo,
abstractType: GraphQLAbstractType,
abstractType: GraphQLAbstractType
): ?GraphQLObjectType | ?Promise<?GraphQLObjectType> {
const possibleTypes = info.schema.getPossibleTypes(abstractType);
const promisedIsTypeOfResults = [];
Expand Down

0 comments on commit 1305360

Please sign in to comment.