diff --git a/src/__tests__/starWarsQuery-test.js b/src/__tests__/starWarsQuery-test.js index 5d3e2dcac0..ea3e51c798 100644 --- a/src/__tests__/starWarsQuery-test.js +++ b/src/__tests__/starWarsQuery-test.js @@ -11,6 +11,12 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import { StarWarsSchema } from './starWarsSchema.js'; import { graphql } from '../graphql'; +import { + GraphQLObjectType, + GraphQLNonNull, + GraphQLSchema, + GraphQLString, +} from '../type'; // 80+ char lines are useful in describe/it, so ignore in this file. /* eslint-disable max-len */ @@ -465,6 +471,61 @@ describe('Star Wars Query Tests', () => { ).to.deep.equal([ [ 'mainHero', 'story' ] ]); }); + it('Full response path is included when fields are non-nullable', async () => { + const A = new GraphQLObjectType({ + name: 'A', + fields: () => ({ + nullableA: { + type: A, + resolve: () => ({}), + }, + nonNullA: { + type: new GraphQLNonNull(A), + resolve: () => ({}), + }, + throws: { + type: new GraphQLNonNull(GraphQLString), + resolve: () => { throw new Error('Catch me if you can'); }, + }, + }), + }); + const queryType = new GraphQLObjectType({ + name: 'query', + fields: () => ({ + nullableA: { + type: A, + resolve: () => ({}) + } + }), + }); + const schema = new GraphQLSchema({ + query: queryType, + }); + + const query = ` + query { + nullableA { + nullableA { + nonNullA { + nonNullA { + throws + } + } + } + } + } + `; + const result = await graphql(schema, query); + const expected = { + nullableA: { + nullableA: null + } + }; + expect(result.data).to.deep.equal(expected); + expect( + result.errors.map(e => e.path)).to.deep.equal( + [ [ 'nullableA', 'nullableA', 'nonNullA', 'nonNullA', 'throws' ] ]); + }); }); });