Skip to content

Commit b33d1a1

Browse files
committed
Add a test for a path with non-nullable fields
1 parent 7a5be6a commit b33d1a1

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/__tests__/starWarsQuery-test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import { expect } from 'chai';
1111
import { describe, it } from 'mocha';
1212
import { StarWarsSchema } from './starWarsSchema.js';
1313
import { graphql } from '../graphql';
14+
import {
15+
GraphQLObjectType,
16+
GraphQLNonNull,
17+
GraphQLSchema,
18+
GraphQLString,
19+
} from '../type';
1420

1521
// 80+ char lines are useful in describe/it, so ignore in this file.
1622
/* eslint-disable max-len */
@@ -465,6 +471,61 @@ describe('Star Wars Query Tests', () => {
465471
).to.deep.equal([ [ 'mainHero', 'story' ] ]);
466472
});
467473

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+
`;
468518

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+
});
469530
});
470531
});

0 commit comments

Comments
 (0)