@@ -13,11 +13,12 @@ import type { ResponseCacheConfig } from '@graphql-mesh/plugin-response-cache';
13
13
import type {
14
14
KeyValueCache ,
15
15
MeshFetch ,
16
- OnFetchHook ,
16
+ MeshFetchRequestInit ,
17
17
} from '@graphql-mesh/types' ;
18
18
import type { FetchInstrumentation } from '@graphql-mesh/utils' ;
19
19
import type { HTTPExecutorOptions } from '@graphql-tools/executor-http' ;
20
20
import type {
21
+ ExecutionRequest ,
21
22
IResolvers ,
22
23
MaybePromise ,
23
24
TypeSource ,
@@ -35,6 +36,7 @@ import type {
35
36
Plugin as YogaPlugin ,
36
37
YogaServerOptions ,
37
38
} from 'graphql-yoga' ;
39
+ import { GraphQLResolveInfo } from 'graphql/type' ;
38
40
import type { UnifiedGraphConfig } from './handleUnifiedGraphConfig' ;
39
41
import type { UseContentEncodingOpts } from './plugins/useContentEncoding' ;
40
42
import type { AgentFactory } from './plugins/useCustomAgent' ;
@@ -96,7 +98,7 @@ export type GatewayPlugin<
96
98
TContext extends Record < string , any > = Record < string , any > ,
97
99
> = YogaPlugin < Partial < TPluginContext > & GatewayContext & TContext > &
98
100
UnifiedGraphPlugin < Partial < TPluginContext > & GatewayContext & TContext > & {
99
- onFetch ?: OnFetchHook < Partial < TPluginContext > & GatewayContext & TContext > ;
101
+ onFetch ?: OnFetchHook < Partial < TPluginContext > & TContext > ;
100
102
onCacheGet ?: OnCacheGetHook ;
101
103
onCacheSet ?: OnCacheSetHook ;
102
104
onCacheDelete ?: OnCacheDeleteHook ;
@@ -112,6 +114,38 @@ export type GatewayPlugin<
112
114
> ;
113
115
} ;
114
116
117
+ export interface OnFetchHookPayload < TContext > {
118
+ url : string ;
119
+ setURL ( url : URL | string ) : void ;
120
+ options : MeshFetchRequestInit ;
121
+ setOptions ( options : MeshFetchRequestInit ) : void ;
122
+ /**
123
+ * The context is not available in cases where "fetch" is done in
124
+ * order to pull a supergraph or do some internal work.
125
+ *
126
+ * The logger will be available in all cases.
127
+ */
128
+ context : ( GatewayContext & TContext ) | { log : Logger } ;
129
+ info : GraphQLResolveInfo ;
130
+ fetchFn : MeshFetch ;
131
+ setFetchFn : ( fetchFn : MeshFetch ) => void ;
132
+ executionRequest ?: ExecutionRequest ;
133
+ endResponse : ( response$ : MaybePromise < Response > ) => void ;
134
+ }
135
+
136
+ export interface OnFetchHookDonePayload {
137
+ response : Response ;
138
+ setResponse : ( response : Response ) => void ;
139
+ }
140
+
141
+ export type OnFetchHookDone = (
142
+ payload : OnFetchHookDonePayload ,
143
+ ) => MaybePromise < void > ;
144
+
145
+ export type OnFetchHook < TContext > = (
146
+ payload : OnFetchHookPayload < TContext > ,
147
+ ) => MaybePromise < void | OnFetchHookDone > ;
148
+
115
149
export type OnCacheGetHook = (
116
150
payload : OnCacheGetHookEventPayload ,
117
151
) => MaybePromise < OnCacheGetHookResult | void > ;
0 commit comments