11/* eslint-disable */
2+ import { GraphQLError } from 'graphql'
23import { describe , expect , test } from 'vitest'
34import { db } from '../../tests/_/db.js'
45import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
56import { schema } from '../../tests/_/schema/schema.js'
7+ import { Errors } from '../lib/errors/__.js'
68import { __typename } from '../Schema/_.js'
79import { create } from './client.js'
810
911// dprint-ignore
10- describe ( 'default' , ( ) => {
12+ describe ( 'default (data) ' , ( ) => {
1113 const client = create ( { schema, schemaIndex } )
1214 test ( `document` , async ( ) => {
1315 await expect ( client . document ( { main : { query : { id : true } } } ) . run ( ) ) . resolves . toEqual ( { id : db . id } )
1416 } )
17+ test ( `document runOrThrow` , async ( ) => {
18+ await expect ( client . document ( { main : { query : { id : true } } } ) . runOrThrow ( ) ) . resolves . toEqual ( { id : db . id } )
19+ } )
20+ test ( `document runOrThrow error` , async ( ) => {
21+ await expect ( client . document ( { main : { query : { error : true } } } ) . runOrThrow ( ) ) . rejects . toEqual ( db . error )
22+ } )
1523 test ( 'raw' , async ( ) => {
1624 await expect ( client . raw ( 'query main {\nid\n}' , { } , 'main' ) ) . resolves . toEqual ( { data : { id : db . id } } )
1725 } )
1826 test ( 'query field method' , async ( ) => {
1927 await expect ( client . query . __typename ( ) ) . resolves . toEqual ( 'Query' )
2028 } )
29+ test ( 'query field method error' , async ( ) => {
30+ await expect ( client . query . error ( ) ) . rejects . toMatchObject ( db . error )
31+ } )
32+ test ( 'query field method error orThrow' , async ( ) => {
33+ await expect ( client . query . errorOrThrow ( ) ) . rejects . toMatchObject ( db . error )
34+ } )
2135 test ( 'query $batch' , async ( ) => {
2236 await expect ( client . query . $batch ( { __typename : true , id : true } ) ) . resolves . toEqual ( { __typename : 'Query' , id : db . id } )
2337 } )
38+ test ( 'query $batchOrThrow error' , async ( ) => {
39+ await expect ( client . query . $batchOrThrow ( { error : true } ) ) . rejects . toMatchObject ( db . error )
40+ } )
2441 test ( 'mutation field method' , async ( ) => {
2542 await expect ( client . mutation . __typename ( ) ) . resolves . toEqual ( 'Mutation' )
2643 } )
@@ -30,20 +47,35 @@ describe('default', () => {
3047} )
3148
3249// dprint-ignore
33- describe ( 'data ' , ( ) => {
34- const client = create ( { schema, schemaIndex, returnMode : 'data ' } )
50+ describe ( 'dataAndAllErrors ' , ( ) => {
51+ const client = create ( { schema, schemaIndex, returnMode : 'dataAndAllErrors ' } )
3552 test ( `document` , async ( ) => {
3653 await expect ( client . document ( { main : { query : { id : true } } } ) . run ( ) ) . resolves . toEqual ( { id : db . id } )
3754 } )
55+ test ( `document runOrThrow` , async ( ) => {
56+ await expect ( client . document ( { main : { query : { id : true } } } ) . runOrThrow ( ) ) . resolves . toEqual ( { id : db . id } )
57+ } )
58+ test ( `document runOrThrow error` , async ( ) => {
59+ await expect ( client . document ( { main : { query : { error : true } } } ) . runOrThrow ( ) ) . rejects . toEqual ( db . error )
60+ } )
3861 test ( 'raw' , async ( ) => {
3962 await expect ( client . raw ( 'query main {\nid\n}' , { } , 'main' ) ) . resolves . toEqual ( { data : { id : db . id } } )
4063 } )
4164 test ( 'query field method' , async ( ) => {
4265 await expect ( client . query . __typename ( ) ) . resolves . toEqual ( 'Query' )
4366 } )
67+ test ( 'query field method error' , async ( ) => {
68+ await expect ( client . query . error ( ) ) . resolves . toMatchObject ( db . error )
69+ } )
70+ test ( 'query field method error orThrow' , async ( ) => {
71+ await expect ( client . query . errorOrThrow ( ) ) . rejects . toMatchObject ( db . error )
72+ } )
4473 test ( 'query $batch' , async ( ) => {
4574 await expect ( client . query . $batch ( { __typename : true , id : true } ) ) . resolves . toEqual ( { __typename : 'Query' , id : db . id } )
4675 } )
76+ test ( 'query $batchOrThrow error' , async ( ) => {
77+ await expect ( client . query . $batchOrThrow ( { error : true } ) ) . rejects . toMatchObject ( db . error )
78+ } )
4779 test ( 'mutation field method' , async ( ) => {
4880 await expect ( client . mutation . __typename ( ) ) . resolves . toEqual ( 'Mutation' )
4981 } )
@@ -58,15 +90,30 @@ describe('graphql', () => {
5890 test ( `document` , async ( ) => {
5991 await expect ( client . document ( { main : { query : { id : true } } } ) . run ( ) ) . resolves . toEqual ( { data : { id : db . id } } ) // dprint-ignore
6092 } )
93+ test ( `document runOrThrow` , async ( ) => {
94+ await expect ( client . document ( { main : { query : { id : true } } } ) . runOrThrow ( ) ) . resolves . toEqual ( { data :{ id : db . id } } )
95+ } )
96+ test ( `document runOrThrow error` , async ( ) => {
97+ await expect ( client . document ( { main : { query : { error : true } } } ) . runOrThrow ( ) ) . rejects . toEqual ( db . error )
98+ } )
6199 test ( 'raw' , async ( ) => {
62100 await expect ( client . raw ( 'query main {\nid\n}' , { } , 'main' ) ) . resolves . toEqual ( { data : { id : db . id } } )
63101 } )
64102 test ( 'query field method' , async ( ) => {
65103 await expect ( client . query . __typename ( ) ) . resolves . toEqual ( { data : { __typename : 'Query' } } )
66104 } )
105+ test ( 'query field method error' , async ( ) => {
106+ await expect ( client . query . error ( ) ) . resolves . toMatchObject ( { errors :db . error [ 'errors' ] } )
107+ } )
108+ test ( 'query field method error orThrow' , async ( ) => {
109+ await expect ( client . query . errorOrThrow ( ) ) . rejects . toMatchObject ( db . error )
110+ } )
67111 test ( 'query $batch' , async ( ) => {
68112 await expect ( client . query . $batch ( { __typename : true , id : true } ) ) . resolves . toEqual ( { data : { __typename : 'Query' , id : db . id } } )
69113 } )
114+ test ( 'query $batchOrThrow error' , async ( ) => {
115+ await expect ( client . query . $batchOrThrow ( { error : true } ) ) . rejects . toMatchObject ( db . error )
116+ } )
70117 test ( 'mutation field method' , async ( ) => {
71118 await expect ( client . mutation . __typename ( ) ) . resolves . toEqual ( { data : { __typename : 'Mutation' } } )
72119 } )
0 commit comments