@@ -6,41 +6,64 @@ import { Graffle } from '../../../../tests/_/schemas/kitchen-sink/graffle/__.js'
6
6
import { schemaDrivenDataMap } from '../../../../tests/_/schemas/kitchen-sink/graffle/modules/SchemaDrivenDataMap.js'
7
7
import type { Query } from '../../../../tests/_/schemas/kitchen-sink/graffle/modules/SelectionSets.js'
8
8
import { schema } from '../../../../tests/_/schemas/kitchen-sink/schema.js'
9
+ import type { Errors } from '../../../lib/errors/__.js'
9
10
import { Select } from '../../2_Select/__.js'
10
11
import { SelectionSetGraphqlMapper } from '../../3_SelectGraphQLMapper/__.js'
11
12
import { graffleMappedToRequest } from '../../5_request/core.js'
12
13
import { injectTypenameOnRootResultFields } from '../../5_request/schemaErrors.js'
13
- import { Throws } from '../Throws/Throws.js'
14
14
15
- const graffle = Graffle . create ( { schema } ) . use ( Throws ( ) )
15
+ const graffle = Graffle
16
+ . create ( { schema } )
17
+ . with ( {
18
+ output : {
19
+ defaults : { errorChannel : `return` } ,
20
+ errors : { schema : `default` } ,
21
+ } ,
22
+ } )
16
23
17
24
describe ( `document` , ( ) => {
18
25
describe ( `query result field` , ( ) => {
19
26
test ( `with __typename` , async ( ) => {
20
- const result = graffle . throws ( ) . document ( {
21
- query : { x : { resultNonNull : { $ : { $case : `ErrorOne` } , __typename : true } } } ,
22
- } )
23
- . run ( )
24
- await expect ( result ) . rejects . toMatchInlineSnapshot ( `[Error: Failure on field resultNonNull: ErrorOne]` )
27
+ const result = ( await graffle
28
+ . document ( { query : { x : { resultNonNull : { $ : { $case : `ErrorOne` } , __typename : true } } } } )
29
+ . run ( ) ) as Errors . ContextualAggregateError
30
+ expect ( result . errors [ 0 ] ) . toMatchInlineSnapshot ( `[Error: Failure on field resultNonNull: ErrorOne]` )
31
+ } )
32
+ test ( `__typename is dynamically added at runtime if missing` , async ( ) => {
33
+ const result = ( await graffle
34
+ . document ( { query : { x : { resultNonNull : { $ : { $case : `ErrorOne` } } } } } )
35
+ . run ( ) ) as Errors . ContextualAggregateError
36
+ expect ( result . errors [ 0 ] ) . toMatchInlineSnapshot ( `[Error: Failure on field resultNonNull: ErrorOne]` )
25
37
} )
26
- test ( `without __typename still works, __typename is dynamically added at runtime` , async ( ) => {
27
- const result = graffle . throws ( ) . document ( { query : { x : { resultNonNull : { $ : { $case : `ErrorOne` } } } } } ) . run ( )
28
- await expect ( result ) . rejects . toMatchInlineSnapshot (
29
- `[Error: Failure on field resultNonNull: ErrorOne]` ,
38
+ test ( `multiple errors` , async ( ) => {
39
+ const result = ( await graffle
40
+ . document ( {
41
+ query : {
42
+ x : {
43
+ result : { $ : { $case : `ErrorOne` } } ,
44
+ resultNonNull : { $ : { $case : `ErrorOne` } } ,
45
+ } ,
46
+ } ,
47
+ } )
48
+ . run ( ) ) as Errors . ContextualAggregateError
49
+
50
+ expect ( result . errors [ 0 ] ) . toMatchInlineSnapshot (
51
+ `[ContextualAggregateError: Two or more schema errors in the execution result.]` ,
30
52
)
31
53
} )
32
- test ( `multiple via alias` , async ( ) => {
33
- const result = graffle . throws ( ) . document ( {
34
- query : {
35
- x : {
36
- resultNonNull : [
37
- [ `resultNonNull` , { $ : { $case : `ErrorOne` } } ] ,
38
- [ `x` , { $ : { $case : `ErrorOne` } } ] ,
39
- ] ,
54
+ test ( `multiple errors via alias` , async ( ) => {
55
+ const result = ( await graffle
56
+ . document ( {
57
+ query : {
58
+ x : {
59
+ resultNonNull : [ [ `resultNonNull` , { $ : { $case : `ErrorOne` } } ] , [ `x` , { $ : { $case : `ErrorOne` } } ] ] ,
60
+ } ,
40
61
} ,
41
- } ,
42
- } ) . run ( )
43
- await expect ( result ) . rejects . toMatchInlineSnapshot (
62
+ } )
63
+ // todo rename to "send" to match gql
64
+ . run ( ) ) as Errors . ContextualAggregateError
65
+
66
+ expect ( result . errors [ 0 ] ) . toMatchInlineSnapshot (
44
67
`[ContextualAggregateError: Two or more schema errors in the execution result.]` ,
45
68
)
46
69
} )
@@ -49,12 +72,12 @@ describe(`document`, () => {
49
72
50
73
describe ( `query non-result field` , ( ) => {
51
74
test ( `without error` , async ( ) => {
52
- await expect ( graffle . throws ( ) . query . objectWithArgs ( { $ : { id : `x` } , id : true } ) ) . resolves . toEqual ( {
75
+ await expect ( graffle . query . objectWithArgs ( { $ : { id : `x` } , id : true } ) ) . resolves . toEqual ( {
53
76
id : `x` ,
54
77
} )
55
78
} )
56
79
test ( `with error` , async ( ) => {
57
- await expect ( graffle . throws ( ) . query . error ( ) ) . rejects . toMatchObject ( db . errorAggregate )
80
+ expect ( await graffle . query . error ( ) ) . toMatchObject ( db . errorAggregate )
58
81
} )
59
82
} )
60
83
@@ -84,17 +107,20 @@ test.each<CasesQuery>([
84
107
expect ( mappedResultWithTypename . document ) . toMatchObject ( mappedResultWithoutTypename . document )
85
108
} )
86
109
87
- // dprint-ignore
88
110
test ( `gql string request` , async ( { kitchenSink } ) => {
89
111
// todo it would be nicer to move the extension use to the fixture but how would we get the static type for that?
90
112
// This makes me think of a feature we need to have. Make it easy to get static types of the client in its various configured states.
91
- const result = await kitchenSink . use ( Throws ( ) ) . throws ( ) . gql `query { resultNonNull (case: Object1) { ... on Object1 { id } } }` . send ( )
113
+ const result = await kitchenSink
114
+ . with ( { output : { errors : { schema : `default` } } } )
115
+ . gql `query { resultNonNull (case: Object1) { ... on Object1 { id } } }`
116
+ . send ( )
92
117
expect ( result ) . toMatchObject ( { resultNonNull : { __typename : `Object1` , id : `abc` } } )
93
118
} )
94
119
95
120
test ( `gql document request` , async ( { kitchenSink } ) => {
96
- const result = await kitchenSink . use ( Throws ( ) ) . throws ( ) . gql (
97
- parse ( `query { resultNonNull (case: Object1) { ... on Object1 { id } } }` ) ,
98
- ) . send ( )
121
+ const result = await kitchenSink
122
+ . with ( { output : { errors : { schema : `default` } } } )
123
+ . gql ( parse ( `query { resultNonNull (case: Object1) { ... on Object1 { id } } }` ) )
124
+ . send ( )
99
125
expect ( result ) . toMatchObject ( { resultNonNull : { __typename : `Object1` , id : `abc` } } )
100
126
} )
0 commit comments