Skip to content

[WIP] Experimental support for semantic-non-null #4192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 39 commits into
base: on-error
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7ca49b2
New GraphQLSemanticNonNull type
benjie Sep 14, 2024
16a2114
Handle isNonNullType
benjie Sep 14, 2024
2b13389
More fixes
benjie Sep 14, 2024
04a8e91
More fixes
benjie Sep 14, 2024
076a735
Yet more updates
benjie Sep 14, 2024
c2196a0
Recognize in introspection, enable disabling null bubbling
benjie Sep 14, 2024
f588046
Lint fixes
benjie Sep 14, 2024
fa3f177
More missing pieces
benjie Sep 14, 2024
b5e81bd
More fixes
benjie Sep 14, 2024
1f6a019
Fix schema
benjie Sep 14, 2024
491f49b
Fix another test
benjie Sep 14, 2024
3a91590
More minor test fixes
benjie Sep 14, 2024
56db880
Fix introspection test
benjie Sep 14, 2024
593ce44
Add support for * to lexer
benjie Sep 14, 2024
1311906
Allow specifying errorPropagation at top level
benjie Sep 14, 2024
9d706d2
Factor into getIntrospectionQuery
benjie Sep 14, 2024
e9f9628
Lint
benjie Sep 14, 2024
eb9b6c8
Prettier
benjie Sep 14, 2024
6ef4bec
Merge branch '16.x.x' into semantic-non-null
benjie Mar 26, 2025
8fcacc8
Switch to errorBehavior, replace contextual introspection to simple i…
benjie Mar 26, 2025
88c5d93
Simplify
benjie Mar 26, 2025
62d1b75
Stricter types: semantic non null may only wrap output types
benjie Mar 26, 2025
96e8b53
Use GraphQLNullableOutputType instead of intersection
benjie Mar 26, 2025
a2169ac
Simpler type
benjie Mar 26, 2025
1ce6880
Only allow GraphQLSemanticNonNull of output type
benjie Mar 26, 2025
97256f0
Tidy
benjie Mar 26, 2025
f464644
Memoize
benjie Mar 26, 2025
2113676
Rename errorBehavior to onError and NULL to NO_PROPAGATE
benjie Mar 27, 2025
95da88d
Centralise the definition of GraphQLErrorBehavior
benjie Mar 27, 2025
a1d2dbe
Lint
benjie Mar 27, 2025
70dc6f8
Prettier
benjie Mar 27, 2025
f3109c3
Implement onError proposal
benjie Mar 27, 2025
a4cec5c
Add tests
benjie Mar 27, 2025
947b040
Test invalid onError is handled
benjie Mar 27, 2025
1bcc31d
Ignore invariant from code coverage
benjie Mar 27, 2025
8338656
Finickity
benjie Mar 27, 2025
c8fdfba
Urghhhhhh
benjie Mar 27, 2025
1cff421
Remove unnecessary resolver causing coverage issue
benjie Mar 27, 2025
c0d54cf
Merge branch 'on-error' into semantic-non-null
benjie Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/error/ErrorBehavior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type GraphQLErrorBehavior = 'PROPAGATE' | 'NO_PROPAGATE' | 'ABORT';

export function isErrorBehavior(
onError: unknown,
): onError is GraphQLErrorBehavior {
return (
onError === 'PROPAGATE' || onError === 'NO_PROPAGATE' || onError === 'ABORT'
);
}
1 change: 1 addition & 0 deletions src/error/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export type {
export { syntaxError } from './syntaxError';

export { locatedError } from './locatedError';
export type { GraphQLErrorBehavior } from './ErrorBehavior';
223 changes: 223 additions & 0 deletions src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ describe('Execute: Handles basic execution tasks', () => {
'rootValue',
'operation',
'variableValues',
'errorBehavior',
);

const operation = document.definitions[0];
Expand All @@ -275,6 +276,7 @@ describe('Execute: Handles basic execution tasks', () => {
schema,
rootValue,
operation,
errorBehavior: 'PROPAGATE',
});

const field = operation.selectionSet.selections[0];
Expand All @@ -285,6 +287,70 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('reflects onError:NO_PROPAGATE via errorBehavior', () => {
let resolvedInfo;
const testType = new GraphQLObjectType({
name: 'Test',
fields: {
test: {
type: GraphQLString,
resolve(_val, _args, _ctx, info) {
resolvedInfo = info;
},
},
},
});
const schema = new GraphQLSchema({ query: testType });

const document = parse('query ($var: String) { result: test }');
const rootValue = { root: 'val' };
const variableValues = { var: 'abc' };

executeSync({
schema,
document,
rootValue,
variableValues,
onError: 'NO_PROPAGATE',
});

expect(resolvedInfo).to.include({
errorBehavior: 'NO_PROPAGATE',
});
});

it('reflects onError:ABORT via errorBehavior', () => {
let resolvedInfo;
const testType = new GraphQLObjectType({
name: 'Test',
fields: {
test: {
type: GraphQLString,
resolve(_val, _args, _ctx, info) {
resolvedInfo = info;
},
},
},
});
const schema = new GraphQLSchema({ query: testType });

const document = parse('query ($var: String) { result: test }');
const rootValue = { root: 'val' };
const variableValues = { var: 'abc' };

executeSync({
schema,
document,
rootValue,
variableValues,
onError: 'ABORT',
});

expect(resolvedInfo).to.include({
errorBehavior: 'ABORT',
});
});

it('populates path correctly with complex types', () => {
let path;
const someObject = new GraphQLObjectType({
Expand Down Expand Up @@ -739,6 +805,163 @@ describe('Execute: Handles basic execution tasks', () => {
});
});

it('Full response path is included for non-nullable fields with onError:NO_PROPAGATE', () => {
const A: GraphQLObjectType = 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 schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'query',
fields: () => ({
nullableA: {
type: A,
resolve: () => ({}),
},
}),
}),
});

const document = parse(`
query {
nullableA {
aliasedA: nullableA {
nonNullA {
anotherA: nonNullA {
throws
}
}
}
}
}
`);

const result = executeSync({ schema, document, onError: 'NO_PROPAGATE' });
expectJSON(result).toDeepEqual({
data: {
nullableA: {
aliasedA: {
nonNullA: {
anotherA: {
throws: null,
},
},
},
},
},
errors: [
{
message: 'Catch me if you can',
locations: [{ line: 7, column: 17 }],
path: ['nullableA', 'aliasedA', 'nonNullA', 'anotherA', 'throws'],
},
],
});
});

it('Full response path is included for non-nullable fields with onError:ABORT', () => {
const A: GraphQLObjectType = 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 schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'query',
fields: () => ({
nullableA: {
type: A,
resolve: () => ({}),
},
}),
}),
});

const document = parse(`
query {
nullableA {
aliasedA: nullableA {
nonNullA {
anotherA: nonNullA {
throws
}
}
}
}
}
`);

const result = executeSync({ schema, document, onError: 'ABORT' });
expectJSON(result).toDeepEqual({
data: null,
errors: [
{
message: 'Catch me if you can',
locations: [{ line: 7, column: 17 }],
path: ['nullableA', 'aliasedA', 'nonNullA', 'anotherA', 'throws'],
},
],
});
});

it('raises request error with invalid onError', () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'query',
fields: () => ({
a: {
type: GraphQLInt,
},
}),
}),
});

const document = parse('{ a }');
const result = executeSync({
schema,
document,
// @ts-expect-error
onError: 'DANCE',
});
expectJSON(result).toDeepEqual({
errors: [
{
message:
'Unsupported `onError` value; supported values are `PROPAGATE`, `NO_PROPAGATE` and `ABORT`.',
},
],
});
});

it('uses the inline operation if no operation name is provided', () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
Expand Down
Loading
Loading