@@ -11,6 +11,12 @@ import { expect } from 'chai';
11
11
import { describe , it } from 'mocha' ;
12
12
import { StarWarsSchema } from './starWarsSchema.js' ;
13
13
import { graphql } from '../graphql' ;
14
+ import {
15
+ GraphQLObjectType ,
16
+ GraphQLNonNull ,
17
+ GraphQLSchema ,
18
+ GraphQLString ,
19
+ } from '../type' ;
14
20
15
21
// 80+ char lines are useful in describe/it, so ignore in this file.
16
22
/* eslint-disable max-len */
@@ -465,6 +471,61 @@ describe('Star Wars Query Tests', () => {
465
471
) . to . deep . equal ( [ [ 'mainHero' , 'story' ] ] ) ;
466
472
} ) ;
467
473
474
+ it ( 'Full response path is included when fields are non-nullable' , async ( ) => {
475
+ const A = new GraphQLObjectType ( {
476
+ name : 'A' ,
477
+ fields : ( ) => ( {
478
+ nullableA : {
479
+ type : A ,
480
+ resolve : ( ) => ( { } ) ,
481
+ } ,
482
+ nonNullA : {
483
+ type : new GraphQLNonNull ( A ) ,
484
+ resolve : ( ) => ( { } ) ,
485
+ } ,
486
+ throws : {
487
+ type : new GraphQLNonNull ( GraphQLString ) ,
488
+ resolve : ( ) => { throw new Error ( 'Catch me if you can' ) ; } ,
489
+ } ,
490
+ } ) ,
491
+ } ) ;
492
+ const queryType = new GraphQLObjectType ( {
493
+ name : 'query' ,
494
+ fields : ( ) => ( {
495
+ nullableA : {
496
+ type : A ,
497
+ resolve : ( ) => ( { } )
498
+ }
499
+ } ) ,
500
+ } ) ;
501
+ const schema = new GraphQLSchema ( {
502
+ query : queryType ,
503
+ } ) ;
504
+
505
+ const query = `
506
+ query {
507
+ nullableA {
508
+ nullableA {
509
+ nonNullA {
510
+ nonNullA {
511
+ throws
512
+ }
513
+ }
514
+ }
515
+ }
516
+ }
517
+ ` ;
468
518
519
+ const result = await graphql ( schema , query ) ;
520
+ const expected = {
521
+ nullableA : {
522
+ nullableA : null
523
+ }
524
+ } ;
525
+ expect ( result . data ) . to . deep . equal ( expected ) ;
526
+ expect (
527
+ result . errors . map ( e => e . path ) ) . to . deep . equal (
528
+ [ [ 'nullableA' , 'nullableA' , 'nonNullA' , 'nonNullA' , 'throws' ] ] ) ;
529
+ } ) ;
469
530
} ) ;
470
531
} ) ;
0 commit comments