-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): add return execution errors example (#1079)
- Loading branch information
1 parent
61fa1fc
commit 3f31e18
Showing
45 changed files
with
515 additions
and
110 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
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
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
17 changes: 17 additions & 0 deletions
17
examples/__outputs__/output|output_return-error.output.txt
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,17 @@ | ||
---------------------------------------- SHOW ---------------------------------------- | ||
ContextualError: There was an error in the extension "anonymous" (use named functions to improve this error message) while running hook "encode". | ||
at runPipeline (/some/path/to/runPipeline.ts:XX:XX) | ||
at async Object.run (/some/path/to/main.ts:XX:XX) | ||
at async run (/some/path/to/client.ts:XX:XX) | ||
at async executeRootType (/some/path/to/client.ts:XX:XX) | ||
at async executeRootTypeField (/some/path/to/client.ts:XX:XX) | ||
at async <anonymous> (/some/path/to/output|output_return-error.ts:XX:XX) { | ||
context: { | ||
hookName: 'encode', | ||
source: 'extension', | ||
extensionName: 'anonymous' | ||
}, | ||
cause: Error: Something went wrong. | ||
at <anonymous> (/some/path/to/output|output_return-error.ts:XX:XX) | ||
at applyBody (/some/path/to/main.ts:XX:XX) | ||
} |
55 changes: 55 additions & 0 deletions
55
...ts__/output|output_return-error_return-error-execution__return-error-execution.output.txt
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,55 @@ | ||
---------------------------------------- SHOW ---------------------------------------- | ||
ContextualAggregateError: One or more errors in the execution result. | ||
at handleOutput (/some/path/to/handleOutput.ts:XX:XX) | ||
at run (/some/path/to/client.ts:XX:XX) | ||
at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) | ||
at async executeRootType (/some/path/to/client.ts:XX:XX) | ||
at async executeRootTypeField (/some/path/to/client.ts:XX:XX) | ||
at async <anonymous> (/some/path/to/output|output_return-error_return-error-execution__return-error-execution.ts:XX:XX) { | ||
context: {}, | ||
cause: undefined, | ||
errors: [ | ||
GraphQLError: [ | ||
{ | ||
"code": "too_small", | ||
"minimum": 1, | ||
"type": "string", | ||
"inclusive": true, | ||
"exact": false, | ||
"message": "Pokemon name cannot be empty.", | ||
"path": [ | ||
"name" | ||
] | ||
} | ||
] | ||
at <anonymous> (/some/path/to/graphqlHTTP.ts:XX:XX) | ||
at Array.map (<anonymous>) | ||
at parseExecutionResult (/some/path/to/graphqlHTTP.ts:XX:XX) | ||
at Object.unpack (/some/path/to/core.ts:XX:XX) | ||
at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) | ||
at async runHook (/some/path/to/runHook.ts:XX:XX) { | ||
path: [ 'addPokemon' ], | ||
locations: undefined, | ||
extensions: [Object: null prototype] {} | ||
} | ||
] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
ContextualError: There was an error in the extension "anonymous" (use named functions to improve this error message) while running hook "encode". | ||
at runPipeline (/some/path/to/runPipeline.ts:XX:XX) | ||
at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) | ||
at async Object.run (/some/path/to/main.ts:XX:XX) | ||
at async run (/some/path/to/client.ts:XX:XX) | ||
at async executeRootType (/some/path/to/client.ts:XX:XX) | ||
at async executeRootTypeField (/some/path/to/client.ts:XX:XX) | ||
at async <anonymous> (/some/path/to/output|output_return-error_return-error-execution__return-error-execution.ts:XX:XX) { | ||
context: { | ||
hookName: 'encode', | ||
source: 'extension', | ||
extensionName: 'anonymous' | ||
}, | ||
cause: Error: Something went wrong. | ||
at <anonymous> (/some/path/to/output|output_return-error_return-error-execution__return-error-execution.ts:XX:XX) | ||
at applyBody (/some/path/to/main.ts:XX:XX) | ||
at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) | ||
} |
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
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,28 @@ | ||
/** | ||
* This example shows how to configure output to have errors returned instead of e.g. thrown. | ||
*/ | ||
|
||
import { Atlas } from './$/generated-clients/atlas/__.js' | ||
import { show } from './$/helpers.js' | ||
|
||
// dprint-ignore | ||
const atlas = Atlas | ||
.create({ | ||
output: { | ||
envelope: false, | ||
defaults: { | ||
errorChannel: `return`, | ||
}, | ||
}, | ||
}) | ||
// dprint-ignore | ||
.use(({ encode: _ }) => { | ||
throw new Error(`Something went wrong.`) | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
}) | ||
|
||
const result = await atlas.query.continents({ name: true }) | ||
type _result = typeof result | ||
// ^? | ||
|
||
show(result) |
45 changes: 45 additions & 0 deletions
45
examples/output|output_return-error_return-error-execution__return-error-execution.ts
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,45 @@ | ||
/** | ||
* This example shows how to configure output to have only certain kinds of errors returned while others thrown. | ||
*/ | ||
|
||
import { Pokemon } from './$/generated-clients/pokemon/__.js' | ||
import { serveSchema, show } from './$/helpers.js' | ||
import { schema } from './$/schemas/pokemon/schema.js' | ||
|
||
const server = await serveSchema({ schema: schema }) | ||
|
||
const pokemon = Pokemon | ||
.create({ | ||
schema: server.url, | ||
output: { | ||
envelope: false, | ||
errors: { | ||
execution: `return`, | ||
other: `throw`, | ||
}, | ||
}, | ||
}) | ||
|
||
// 1. The __execution__ error of an empty Pokemon name will be ***returned***. | ||
|
||
type _result = typeof result | ||
const result = await pokemon.mutation.addPokemon({ | ||
$: { name: ``, hp: 1, defense: 0, attack: 0 }, | ||
name: true, | ||
}) | ||
show(result) | ||
|
||
// 2. The __other__ error, in this case from the inline extension, will be ***thrown***. | ||
|
||
try { | ||
await pokemon | ||
.use(({ encode: _ }) => { | ||
throw new Error(`Something went wrong.`) | ||
}) | ||
.query | ||
.pokemon({ name: true }) | ||
} catch (error) { | ||
show(error) | ||
} | ||
|
||
await server.stop() |
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
Oops, something went wrong.