-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for @experimental_disableErrorPropagation (#4348)
~This pull request adds support for `@onError(action: NULL)` to disable error propagation for error aware clients:~ This pull request adds support for `@experimental_disableErrorPropagation` to disable error propagation for error aware clients: ```graphql """ Disables error propagation. """ directive @experimental_disableErrorPropagation on QUERY | MUTATION | SUBSCRIPTION ``` I'm not super used to write TypeScript, feel free to amend the PR as needed but I figured it'd be good to have. The logic is unconditional. The matching [graphql-java](graphql-java/graphql-java#3772) PR has a specific opt-in flag so that it's not enabled by accident in the very unlikely event that a schema already contains a matching directive. Let me know if this is an issue. Many thanks @JoviDeCroock for pointing me in the right direction 🙏 See graphql/nullability-wg#85 See graphql/graphql-spec#1050 --------- Co-authored-by: Jovi De Croock <[email protected]>
- Loading branch information
1 parent
72c9044
commit f17d05a
Showing
3 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { describe, it } from 'mocha'; | ||
|
||
import { expectJSON } from '../../__testUtils__/expectJSON.js'; | ||
|
||
import type { PromiseOrValue } from '../../jsutils/PromiseOrValue.js'; | ||
|
||
import { parse } from '../../language/parser.js'; | ||
|
||
import { buildSchema } from '../../utilities/buildASTSchema.js'; | ||
|
||
import { execute } from '../execute.js'; | ||
import type { ExecutionResult } from '../types.js'; | ||
|
||
const syncError = new Error('bar'); | ||
|
||
const throwingData = { | ||
foo() { | ||
throw syncError; | ||
}, | ||
}; | ||
|
||
const schema = buildSchema(` | ||
type Query { | ||
foo : Int! | ||
} | ||
directive @experimental_disableErrorPropagation on QUERY | MUTATION | SUBSCRIPTION | ||
`); | ||
|
||
function executeQuery( | ||
query: string, | ||
rootValue: unknown, | ||
): PromiseOrValue<ExecutionResult> { | ||
return execute({ schema, document: parse(query), rootValue }); | ||
} | ||
|
||
describe('Execute: handles errors', () => { | ||
it('with `@experimental_disableErrorPropagation returns null', async () => { | ||
const query = ` | ||
query getFoo @experimental_disableErrorPropagation { | ||
foo | ||
} | ||
`; | ||
const result = await executeQuery(query, throwingData); | ||
expectJSON(result).toDeepEqual({ | ||
data: { foo: null }, | ||
errors: [ | ||
{ | ||
message: 'bar', | ||
path: ['foo'], | ||
locations: [{ line: 3, column: 9 }], | ||
}, | ||
], | ||
}); | ||
}); | ||
it('without `experimental_disableErrorPropagation` propagates the error', async () => { | ||
const query = ` | ||
query getFoo { | ||
foo | ||
} | ||
`; | ||
const result = await executeQuery(query, throwingData); | ||
expectJSON(result).toDeepEqual({ | ||
data: null, | ||
errors: [ | ||
{ | ||
message: 'bar', | ||
path: ['foo'], | ||
locations: [{ line: 3, column: 9 }], | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters