Skip to content

Commit

Permalink
Improve coercion error messages
Browse files Browse the repository at this point in the history
* Remove redundant falsy check for runtimeType

* Replace silent conversion to null with an invariant and a useful error message

* Add an error message for unexpected return value from resolveType

* Make sure null and undefined mean could not determine type while false or 0 indicates wrong return type
  • Loading branch information
JeffRMoore authored and leebyron committed Apr 5, 2016
1 parent 3974438 commit dea5aac
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,19 @@ function completeAbstractValue(
returnType.resolveType(result, exeContext.contextValue, info) :
defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);

if (!runtimeType) {
return null;
}
invariant(
!isNullish(runtimeType),
`Could not determine runtime type of value "${result}" for field ${
info.parentType}.${info.fieldName}.`
);
invariant(
runtimeType instanceof GraphQLObjectType,
`resolveType must return an instance of GraphQLObjectType for field ${
info.parentType}.${info.fieldName}, received "${runtimeType}".`
);

const schema = exeContext.schema;
if (runtimeType && !schema.isPossibleType(returnType, runtimeType)) {
if (!schema.isPossibleType(returnType, runtimeType)) {
throw new GraphQLError(
`Runtime Object type "${runtimeType}" is not a possible type ` +
`for "${returnType}".`,
Expand Down

0 comments on commit dea5aac

Please sign in to comment.