Skip to content

Commit 8bad454

Browse files
committed
Switch to having more granular errors
1 parent b585c4c commit 8bad454

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

src/execution/__tests__/lists-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe('Execute: Handles list nullability', () => {
210210
errors: [
211211
{
212212
message:
213-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to [Int]!',
213+
'Cannot return null for non-nullable field DataType.test.',
214214
locations: [{ line: 1, column: 10 }],
215215
path: ['nest', 'test'],
216216
},
@@ -239,7 +239,7 @@ describe('Execute: Handles list nullability', () => {
239239
errors: [
240240
{
241241
message:
242-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to [Int]!',
242+
'Cannot return null for non-nullable field DataType.test.',
243243
locations: [{ line: 1, column: 10 }],
244244
path: ['nest', 'test'],
245245
},
@@ -313,7 +313,7 @@ describe('Execute: Handles list nullability', () => {
313313
errors: [
314314
{
315315
message:
316-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to Int!',
316+
'Cannot return null for non-nullable field DataType.test.',
317317
locations: [{ line: 1, column: 10 }],
318318
path: ['nest', 'test', 1],
319319
},
@@ -337,7 +337,7 @@ describe('Execute: Handles list nullability', () => {
337337
errors: [
338338
{
339339
message:
340-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to Int!',
340+
'Cannot return null for non-nullable field DataType.test.',
341341
locations: [{ line: 1, column: 10 }],
342342
path: ['nest', 'test', 1],
343343
},
@@ -380,7 +380,7 @@ describe('Execute: Handles list nullability', () => {
380380
errors: [
381381
{
382382
message:
383-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to Int!',
383+
'Cannot return null for non-nullable field DataType.test.',
384384
locations: [{ line: 1, column: 10 }],
385385
path: ['nest', 'test', 1],
386386
},
@@ -424,7 +424,7 @@ describe('Execute: Handles list nullability', () => {
424424
errors: [
425425
{
426426
message:
427-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to Int!',
427+
'Cannot return null for non-nullable field DataType.test.',
428428
locations: [{ line: 1, column: 10 }],
429429
path: ['nest', 'test', 1],
430430
},
@@ -439,7 +439,7 @@ describe('Execute: Handles list nullability', () => {
439439
errors: [
440440
{
441441
message:
442-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to [Int!]!',
442+
'Cannot return null for non-nullable field DataType.test.',
443443
locations: [{ line: 1, column: 10 }],
444444
path: ['nest', 'test'],
445445
},
@@ -461,7 +461,7 @@ describe('Execute: Handles list nullability', () => {
461461
errors: [
462462
{
463463
message:
464-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to Int!',
464+
'Cannot return null for non-nullable field DataType.test.',
465465
locations: [{ line: 1, column: 10 }],
466466
path: ['nest', 'test', 1],
467467
},
@@ -476,7 +476,7 @@ describe('Execute: Handles list nullability', () => {
476476
errors: [
477477
{
478478
message:
479-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to [Int!]!',
479+
'Cannot return null for non-nullable field DataType.test.',
480480
locations: [{ line: 1, column: 10 }],
481481
path: ['nest', 'test'],
482482
},
@@ -514,7 +514,7 @@ describe('Execute: Handles list nullability', () => {
514514
errors: [
515515
{
516516
message:
517-
'Cannot return null for non-nullable field DataType.test. Value null cannot be converted to Int!',
517+
'Cannot return null for non-nullable field DataType.test.',
518518
locations: [{ line: 1, column: 10 }],
519519
path: ['nest', 'test', 1],
520520
},

src/execution/__tests__/nonnull-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('Execute: handles non-nullable types', () => {
177177
errors: [
178178
{
179179
message:
180-
'Cannot return null for non-nullable field DataType.syncNonNull. Value null cannot be converted to String!',
180+
'Cannot return null for non-nullable field DataType.syncNonNull.',
181181
path: ['syncNest', 'syncNonNull'],
182182
locations: [{ line: 4, column: 11 }],
183183
},
@@ -216,7 +216,7 @@ describe('Execute: handles non-nullable types', () => {
216216
errors: [
217217
{
218218
message:
219-
'Cannot return null for non-nullable field DataType.syncNonNull. Value null cannot be converted to String!',
219+
'Cannot return null for non-nullable field DataType.syncNonNull.',
220220
path: ['promiseNest', 'syncNonNull'],
221221
locations: [{ line: 4, column: 11 }],
222222
},
@@ -409,7 +409,7 @@ describe('Execute: handles non-nullable types', () => {
409409
errors: [
410410
{
411411
message:
412-
'Cannot return null for non-nullable field DataType.syncNonNull. Value null cannot be converted to String!',
412+
'Cannot return null for non-nullable field DataType.syncNonNull.',
413413
path: [
414414
'syncNest',
415415
'syncNonNullNest',
@@ -422,7 +422,7 @@ describe('Execute: handles non-nullable types', () => {
422422
},
423423
{
424424
message:
425-
'Cannot return null for non-nullable field DataType.syncNonNull. Value null cannot be converted to String!',
425+
'Cannot return null for non-nullable field DataType.syncNonNull.',
426426
path: [
427427
'promiseNest',
428428
'syncNonNullNest',
@@ -435,7 +435,7 @@ describe('Execute: handles non-nullable types', () => {
435435
},
436436
{
437437
message:
438-
'Cannot return null for non-nullable field DataType.promiseNonNull. Value null cannot be converted to String!',
438+
'Cannot return null for non-nullable field DataType.promiseNonNull.',
439439
path: [
440440
'anotherNest',
441441
'syncNonNullNest',
@@ -448,7 +448,7 @@ describe('Execute: handles non-nullable types', () => {
448448
},
449449
{
450450
message:
451-
'Cannot return null for non-nullable field DataType.promiseNonNull. Value null cannot be converted to String!',
451+
'Cannot return null for non-nullable field DataType.promiseNonNull.',
452452
path: [
453453
'anotherPromiseNest',
454454
'syncNonNullNest',
@@ -535,7 +535,7 @@ describe('Execute: handles non-nullable types', () => {
535535
errors: [
536536
{
537537
message:
538-
'Cannot return null for non-nullable field DataType.syncNonNull. Value null cannot be converted to String!',
538+
'Cannot return null for non-nullable field DataType.syncNonNull.',
539539
path: ['syncNonNull'],
540540
locations: [{ line: 3, column: 9 }],
541541
},

src/execution/execute.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -862,13 +862,18 @@ function completeValue(
862862
result,
863863
);
864864
if (completed === null) {
865-
throw new Error(
866-
`Cannot return null for non-nullable field ${info.parentType.name}.${
867-
info.fieldName
868-
}. Value ${inspect(result)} cannot be converted to ${inspect(
869-
returnType,
870-
)}`,
871-
);
865+
if (result == null) {
866+
throw new Error(
867+
`Cannot return null for non-nullable field ` +
868+
`${info.parentType.name}.${info.fieldName}.`,
869+
);
870+
} else {
871+
throw new Error(
872+
`Cannot coerce '${inspect(result)}' into type ` +
873+
`${inspect(returnType)} for non-nullable field ` +
874+
`${info.parentType.name}.${info.fieldName}`,
875+
);
876+
}
872877
}
873878
return completed;
874879
}

0 commit comments

Comments
 (0)