-
Notifications
You must be signed in to change notification settings - Fork 2k
Add support for @experimental_disableErrorPropagation #4348
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d9c350f
Add support for @onError
martinbonnin 5d4bec2
typo
martinbonnin 6409cf6
propagateErrors -> errorPropagation
martinbonnin f96492c
Rename to @experimental_disableErrorPropagation
martinbonnin 26e5375
Forgot to add file
martinbonnin 2aaf644
Update src/execution/__tests__/errorPropagation-test.ts
martinbonnin aec37aa
Fix lint
martinbonnin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.