Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit553006b

Browse files
authored
fix: await response middleware (#810)
1 parentd368c16 commit553006b

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

‎src/legacy/classes/GraphQLClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class GraphQLClient {
7575
})
7676

7777
if(responseMiddleware){
78-
responseMiddleware(response,{
78+
awaitresponseMiddleware(response,{
7979
operationName:document.operationName,
8080
variables,
8181
url:this.url,
@@ -146,7 +146,7 @@ export class GraphQLClient {
146146
})
147147

148148
if(responseMiddleware){
149-
responseMiddleware(response,{
149+
awaitresponseMiddleware(response,{
150150
operationName:analyzedDocument.operationName,
151151
variables:requestOptions.variables,
152152
url:this.url,
@@ -222,7 +222,7 @@ export class GraphQLClient {
222222
})
223223

224224
if(this.requestConfig.responseMiddleware){
225-
this.requestConfig.responseMiddleware(response,{
225+
awaitthis.requestConfig.responseMiddleware(response,{
226226
operationName:undefined,
227227
variables,
228228
url:this.url,

‎src/legacy/helpers/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
importtype{TypedDocumentNode}from'@graphql-typed-document-node/core'
22
importtype{GraphQLError}from'graphql/error/GraphQLError.js'
33
importtype{DocumentNode}from'graphql/language/ast.js'
4-
importtype{MaybeLazy,RemoveIndex}from'../../lib/prelude.js'
4+
importtype{MaybeLazy,MaybePromise,RemoveIndex}from'../../lib/prelude.js'
55
importtype{ClientError}from'../classes/ClientError.js'
66

77
exporttypeFetch=typeoffetch
@@ -93,7 +93,7 @@ export type RequestOptions<V extends Variables = Variables, T = unknown> =
9393
exporttypeResponseMiddleware=(
9494
response:GraphQLClientResponse<unknown>|ClientError|Error,
9595
request:RequestExtendedInit,
96-
)=>void
96+
)=>MaybePromise<void>
9797

9898
exporttypeRequestMiddleware<VextendsVariables=Variables>=(
9999
request:RequestExtendedInit<V>,

‎src/lib/prelude.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,5 @@ export function assertObject(v: unknown): asserts v is object {
247247
}
248248

249249
exporttypeStringKeyof<T>=keyofT&string
250+
251+
exporttypeMaybePromise<T>=T|Promise<T>

‎tests/legacy/middleware.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import{expect,test}from'vitest'
2+
import{GraphQLClient}from'../../src/entrypoints/main.js'
3+
import{setupMockServer}from'./__helpers.js'
4+
5+
constctx=setupMockServer()
6+
7+
test(`throwing an error in response middleware is not swalled`,async()=>{
8+
constclient=newGraphQLClient(ctx.url,{
9+
// eslint-disable-next-line
10+
responseMiddleware:async()=>{
11+
thrownewError(`TEST ERROR`)
12+
},
13+
})
14+
ctx.res()
15+
awaitexpect(client.request(`{ me { id } }`)).rejects.toMatchInlineSnapshot(`[Error: TEST ERROR]`)
16+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp