Skip to content

Commit 0d89dd1

Browse files
committed
Add tests
1 parent 46ac468 commit 0d89dd1

File tree

1 file changed

+192
-0
lines changed

1 file changed

+192
-0
lines changed

src/execution/__tests__/executor-test.ts

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,70 @@ describe('Execute: Handles basic execution tasks', () => {
288288
});
289289
});
290290

291+
it('reflects onError:NO_PROPAGATE via errorBehavior', () => {
292+
let resolvedInfo;
293+
const testType = new GraphQLObjectType({
294+
name: 'Test',
295+
fields: {
296+
test: {
297+
type: GraphQLString,
298+
resolve(_val, _args, _ctx, info) {
299+
resolvedInfo = info;
300+
},
301+
},
302+
},
303+
});
304+
const schema = new GraphQLSchema({ query: testType });
305+
306+
const document = parse('query ($var: String) { result: test }');
307+
const rootValue = { root: 'val' };
308+
const variableValues = { var: 'abc' };
309+
310+
executeSync({
311+
schema,
312+
document,
313+
rootValue,
314+
variableValues,
315+
onError: 'NO_PROPAGATE',
316+
});
317+
318+
expect(resolvedInfo).to.include({
319+
errorBehavior: 'NO_PROPAGATE',
320+
});
321+
});
322+
323+
it('reflects onError:ABORT via errorBehavior', () => {
324+
let resolvedInfo;
325+
const testType = new GraphQLObjectType({
326+
name: 'Test',
327+
fields: {
328+
test: {
329+
type: GraphQLString,
330+
resolve(_val, _args, _ctx, info) {
331+
resolvedInfo = info;
332+
},
333+
},
334+
},
335+
});
336+
const schema = new GraphQLSchema({ query: testType });
337+
338+
const document = parse('query ($var: String) { result: test }');
339+
const rootValue = { root: 'val' };
340+
const variableValues = { var: 'abc' };
341+
342+
executeSync({
343+
schema,
344+
document,
345+
rootValue,
346+
variableValues,
347+
onError: 'ABORT',
348+
});
349+
350+
expect(resolvedInfo).to.include({
351+
errorBehavior: 'ABORT',
352+
});
353+
});
354+
291355
it('populates path correctly with complex types', () => {
292356
let path;
293357
const someObject = new GraphQLObjectType({
@@ -742,6 +806,134 @@ describe('Execute: Handles basic execution tasks', () => {
742806
});
743807
});
744808

809+
it('Full response path is included for non-nullable fields with onError:NO_PROPAGATE', () => {
810+
const A: GraphQLObjectType = new GraphQLObjectType({
811+
name: 'A',
812+
fields: () => ({
813+
nullableA: {
814+
type: A,
815+
resolve: () => ({}),
816+
},
817+
nonNullA: {
818+
type: new GraphQLNonNull(A),
819+
resolve: () => ({}),
820+
},
821+
throws: {
822+
type: new GraphQLNonNull(GraphQLString),
823+
resolve: () => {
824+
throw new Error('Catch me if you can');
825+
},
826+
},
827+
}),
828+
});
829+
const schema = new GraphQLSchema({
830+
query: new GraphQLObjectType({
831+
name: 'query',
832+
fields: () => ({
833+
nullableA: {
834+
type: A,
835+
resolve: () => ({}),
836+
},
837+
}),
838+
}),
839+
});
840+
841+
const document = parse(`
842+
query {
843+
nullableA {
844+
aliasedA: nullableA {
845+
nonNullA {
846+
anotherA: nonNullA {
847+
throws
848+
}
849+
}
850+
}
851+
}
852+
}
853+
`);
854+
855+
const result = executeSync({ schema, document, onError: 'NO_PROPAGATE' });
856+
expectJSON(result).toDeepEqual({
857+
data: {
858+
nullableA: {
859+
aliasedA: {
860+
nonNullA: {
861+
anotherA: {
862+
throws: null,
863+
},
864+
},
865+
},
866+
},
867+
},
868+
errors: [
869+
{
870+
message: 'Catch me if you can',
871+
locations: [{ line: 7, column: 17 }],
872+
path: ['nullableA', 'aliasedA', 'nonNullA', 'anotherA', 'throws'],
873+
},
874+
],
875+
});
876+
});
877+
878+
it('Full response path is included for non-nullable fields with onError:ABORT', () => {
879+
const A: GraphQLObjectType = new GraphQLObjectType({
880+
name: 'A',
881+
fields: () => ({
882+
nullableA: {
883+
type: A,
884+
resolve: () => ({}),
885+
},
886+
nonNullA: {
887+
type: new GraphQLNonNull(A),
888+
resolve: () => ({}),
889+
},
890+
throws: {
891+
type: new GraphQLNonNull(GraphQLString),
892+
resolve: () => {
893+
throw new Error('Catch me if you can');
894+
},
895+
},
896+
}),
897+
});
898+
const schema = new GraphQLSchema({
899+
query: new GraphQLObjectType({
900+
name: 'query',
901+
fields: () => ({
902+
nullableA: {
903+
type: A,
904+
resolve: () => ({}),
905+
},
906+
}),
907+
}),
908+
});
909+
910+
const document = parse(`
911+
query {
912+
nullableA {
913+
aliasedA: nullableA {
914+
nonNullA {
915+
anotherA: nonNullA {
916+
throws
917+
}
918+
}
919+
}
920+
}
921+
}
922+
`);
923+
924+
const result = executeSync({ schema, document, onError: 'ABORT' });
925+
expectJSON(result).toDeepEqual({
926+
data: null,
927+
errors: [
928+
{
929+
message: 'Catch me if you can',
930+
locations: [{ line: 7, column: 17 }],
931+
path: ['nullableA', 'aliasedA', 'nonNullA', 'anotherA', 'throws'],
932+
},
933+
],
934+
});
935+
});
936+
745937
it('uses the inline operation if no operation name is provided', () => {
746938
const schema = new GraphQLSchema({
747939
query: new GraphQLObjectType({

0 commit comments

Comments
 (0)