Skip to content

Commit

Permalink
Add a test for a path with non-nullable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Slava committed Jun 10, 2016
1 parent 7a5be6a commit b33d1a1
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/__tests__/starWarsQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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' ] ]);
});
});
});

0 comments on commit b33d1a1

Please sign in to comment.