Skip to content

Commit

Permalink
execute: Forbid to return null from serialize function (#3231)
Browse files Browse the repository at this point in the history
Fixes #1579
  • Loading branch information
IvanGoncharov committed Aug 11, 2021
1 parent 4f21cdc commit 0fef3c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/execution/__tests__/executor-test.ts
Expand Up @@ -1123,7 +1123,7 @@ describe('Execute: Handles basic execution tasks', () => {
errors: [
{
message:
'Expected a value of type "CustomScalar" but received: "CUSTOM_VALUE"',
'Expected `CustomScalar.serialize("CUSTOM_VALUE")` to return non-nullable value, returned: undefined',
locations: [{ line: 1, column: 3 }],
path: ['customScalar'],
},
Expand Down
6 changes: 3 additions & 3 deletions src/execution/execute.ts
Expand Up @@ -750,10 +750,10 @@ function completeLeafValue(
result: unknown,
): unknown {
const serializedResult = returnType.serialize(result);
if (serializedResult === undefined) {
if (serializedResult == null) {
throw new Error(
`Expected a value of type "${inspect(returnType)}" but ` +
`received: ${inspect(result)}`,
`Expected \`${inspect(returnType)}.serialize(${inspect(result)})\` to ` +
`return non-nullable value, returned: ${inspect(serializedResult)}`,
);
}
return serializedResult;
Expand Down

0 comments on commit 0fef3c4

Please sign in to comment.