@@ -118,10 +118,17 @@ describe('graphqlRequestBaseQuery', () => {
118118 { } ,
119119 )
120120
121- expect ( result . error ) . toBeDefined ( )
122- expect ( result . error ) . toHaveProperty ( 'name' )
123- expect ( result . error ) . toHaveProperty ( 'message' )
124- expect ( result . meta ) . toBeDefined ( )
121+ expect ( result ) . toEqual ( {
122+ error : {
123+ name : expect . any ( String ) ,
124+ message : expect . any ( String ) ,
125+ stack : expect . any ( String ) ,
126+ } ,
127+ meta : {
128+ request : expect . any ( Object ) ,
129+ response : expect . any ( Object ) ,
130+ } ,
131+ } )
125132 } )
126133
127134 it ( 'includes request and response in meta for ClientError' , async ( ) => {
@@ -146,43 +153,58 @@ describe('graphqlRequestBaseQuery', () => {
146153 expect ( result . meta ) . toHaveProperty ( 'response' )
147154 } )
148155
149- it ( 'throws network errors (non-ClientError) - documents current bug ' , async ( ) => {
156+ it ( 'returns network errors (non-ClientError) instead of throwing ' , async ( ) => {
150157 const networkError = new Error ( 'Network timeout' )
151158 const mockClient = {
152159 request : vi . fn ( ) . mockRejectedValue ( networkError ) ,
153160 } as unknown as GraphQLClient
154161
155162 const baseQuery = graphqlRequestBaseQuery ( { client : mockClient } )
156163
157- // Currently throws - this test documents the bug that causes infinite retries
158- await expect (
159- baseQuery (
160- {
161- document : 'query { user { id } }' ,
162- } ,
163- createMockApi ( ) ,
164- { } ,
165- ) ,
166- ) . rejects . toThrow ( 'Network timeout' )
164+ const result = await baseQuery (
165+ {
166+ document : 'query { user { id } }' ,
167+ } ,
168+ createMockApi ( ) ,
169+ { } ,
170+ )
171+
172+ // Should return error instead of throwing
173+ expect ( result ) . toEqual ( {
174+ error : {
175+ name : 'Error' ,
176+ message : 'Network timeout' ,
177+ stack : expect . any ( String ) ,
178+ } ,
179+ meta : { } ,
180+ } )
167181 } )
168182
169- it ( 'throws fetch errors - documents current bug ' , async ( ) => {
183+ it ( 'returns fetch errors instead of throwing ' , async ( ) => {
170184 const fetchError = new Error ( 'Failed to fetch' )
171185 const mockClient = {
172186 request : vi . fn ( ) . mockRejectedValue ( fetchError ) ,
173187 } as unknown as GraphQLClient
174188
175189 const baseQuery = graphqlRequestBaseQuery ( { client : mockClient } )
176190
177- await expect (
178- baseQuery (
179- {
180- document : 'query { test }' ,
181- } ,
182- createMockApi ( ) ,
183- { } ,
184- ) ,
185- ) . rejects . toThrow ( 'Failed to fetch' )
191+ const result = await baseQuery (
192+ {
193+ document : 'query { test }' ,
194+ } ,
195+ createMockApi ( ) ,
196+ { } ,
197+ )
198+
199+ // Should return error instead of throwing
200+ expect ( result ) . toEqual ( {
201+ error : {
202+ name : 'Error' ,
203+ message : 'Failed to fetch' ,
204+ stack : expect . any ( String ) ,
205+ } ,
206+ meta : { } ,
207+ } )
186208 } )
187209
188210 it ( 'uses custom error handler when provided' , async ( ) => {
@@ -243,9 +265,17 @@ describe('graphqlRequestBaseQuery', () => {
243265 { } ,
244266 )
245267
246- expect ( result . error ) . toHaveProperty ( 'name' )
247- expect ( result . error ) . toHaveProperty ( 'message' )
248- expect ( result . error ) . toHaveProperty ( 'stack' )
268+ expect ( result ) . toEqual ( {
269+ error : {
270+ name : expect . any ( String ) ,
271+ message : expect . any ( String ) ,
272+ stack : expect . any ( String ) ,
273+ } ,
274+ meta : {
275+ request : expect . any ( Object ) ,
276+ response : expect . any ( Object ) ,
277+ } ,
278+ } )
249279 } )
250280 } )
251281
0 commit comments