@graphql-mesh/plugin-jwt-auth 1.5.3 → 1.5.4-alpha-e65b24fb75937f0f9376611da3af4e28a4b0200e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +637 -0
- package/dist/index.cjs +86 -0
- package/dist/index.d.cts +332 -0
- package/dist/index.d.ts +332 -0
- package/dist/index.js +61 -0
- package/package.json +41 -29
- package/cjs/index.js +0 -65
- package/cjs/package.json +0 -1
- package/esm/index.js +0 -55
- package/typings/index.d.cts +0 -28
- package/typings/index.d.ts +0 -28
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var pluginJwt = require('@graphql-yoga/plugin-jwt');
|
|
6
|
+
|
|
7
|
+
function useForwardedJWT(config) {
|
|
8
|
+
const extensionsJwtFieldName = config.extensionsFieldName ?? "jwt";
|
|
9
|
+
const extendContextFieldName = config.extendContextFieldName ?? "jwt";
|
|
10
|
+
return {
|
|
11
|
+
onContextBuilding({ context, extendContext }) {
|
|
12
|
+
if (context.params.extensions?.[extensionsJwtFieldName]) {
|
|
13
|
+
const jwt = context.params.extensions[extensionsJwtFieldName];
|
|
14
|
+
extendContext({
|
|
15
|
+
[extendContextFieldName]: jwt
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function useJWT(options) {
|
|
22
|
+
const forwardPayload = options?.forward?.payload ?? true;
|
|
23
|
+
const forwardToken = options?.forward?.token ?? false;
|
|
24
|
+
const shouldForward = forwardPayload || forwardToken;
|
|
25
|
+
const fieldName = options?.forward?.extensionsFieldName ?? "jwt";
|
|
26
|
+
return {
|
|
27
|
+
onPluginInit({ addPlugin }) {
|
|
28
|
+
const jwtPlugin = pluginJwt.useJWT(options);
|
|
29
|
+
addPlugin(
|
|
30
|
+
// @ts-expect-error fix useYogaJWT typings to inherit the context
|
|
31
|
+
jwtPlugin
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
// When a subgraph is about to be executed, we check if the initial request has a JWT token
|
|
35
|
+
// that needs to be passed. At the moment, only GraphQL subgraphs will have the option to forward tokens/payload.
|
|
36
|
+
// The JWT info will be passed to the subgraph execution request.
|
|
37
|
+
onSubgraphExecute({
|
|
38
|
+
executionRequest,
|
|
39
|
+
subgraphName,
|
|
40
|
+
setExecutionRequest,
|
|
41
|
+
logger
|
|
42
|
+
}) {
|
|
43
|
+
if (shouldForward && executionRequest.context?.jwt) {
|
|
44
|
+
const jwtData = {
|
|
45
|
+
payload: forwardPayload ? executionRequest.context.jwt.payload : void 0,
|
|
46
|
+
token: forwardToken ? executionRequest.context.jwt.token : void 0
|
|
47
|
+
};
|
|
48
|
+
logger?.debug(
|
|
49
|
+
`Forwarding JWT payload to subgraph ${subgraphName}, payload: `,
|
|
50
|
+
jwtData.payload
|
|
51
|
+
);
|
|
52
|
+
setExecutionRequest({
|
|
53
|
+
...executionRequest,
|
|
54
|
+
extensions: {
|
|
55
|
+
...executionRequest.extensions,
|
|
56
|
+
[fieldName]: jwtData
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Object.defineProperty(exports, "createInlineSigningKeyProvider", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return pluginJwt.createInlineSigningKeyProvider; }
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, "createRemoteJwksSigningKeyProvider", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () { return pluginJwt.createRemoteJwksSigningKeyProvider; }
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "extractFromConnectionParams", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () { return pluginJwt.extractFromConnectionParams; }
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, "extractFromCookie", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () { return pluginJwt.extractFromCookie; }
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "extractFromHeader", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () { return pluginJwt.extractFromHeader; }
|
|
83
|
+
});
|
|
84
|
+
exports.default = useJWT;
|
|
85
|
+
exports.useForwardedJWT = useForwardedJWT;
|
|
86
|
+
exports.useJWT = useJWT;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { Plugin, YogaInitialContext, Instrumentation as Instrumentation$2 } from 'graphql-yoga';
|
|
2
|
+
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
3
|
+
import { ExecutionRequest, ExecutionResult, Executor, MaybePromise as MaybePromise$1, Maybe } from '@graphql-tools/utils';
|
|
4
|
+
import { GraphQLSchema, OperationTypeNode, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLOutputType, GraphQLError, SelectionSetNode, FragmentDefinitionNode, FieldNode, ExecutionResult as ExecutionResult$1, SelectionNode } from 'graphql';
|
|
5
|
+
import { Logger, MeshFetch, KeyValueCache, OnFetchHook } from '@graphql-mesh/types';
|
|
6
|
+
import DataLoader from 'dataloader';
|
|
7
|
+
import { GraphQLResolveInfo as GraphQLResolveInfo$1, GraphQLOutputType as GraphQLOutputType$1 } from 'graphql/type';
|
|
8
|
+
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
9
|
+
import { FetchInstrumentation } from '@graphql-mesh/utils';
|
|
10
|
+
import { JwtPluginOptions, JWTExtendContextFields } from '@graphql-yoga/plugin-jwt';
|
|
11
|
+
export { ExtractTokenFunction, GetSigningKeyFunction, JWTExtendContextFields, JwtPluginOptions, createInlineSigningKeyProvider, createRemoteJwksSigningKeyProvider, extractFromConnectionParams, extractFromCookie, extractFromHeader } from '@graphql-yoga/plugin-jwt';
|
|
12
|
+
|
|
13
|
+
type TopicDataMap = Record<string, any>;
|
|
14
|
+
interface HivePubSub<Data extends TopicDataMap = TopicDataMap> {
|
|
15
|
+
/** @deprecated Please use {@link subscribedTopics} if implemented instead. This method will be removed in next major release. */
|
|
16
|
+
getEventNames(): Iterable<keyof Data>;
|
|
17
|
+
/** @important This method will be required starting next major release. */
|
|
18
|
+
subscribedTopics?(): Iterable<keyof Data>;
|
|
19
|
+
publish<Topic extends keyof Data>(topic: Topic, data: Data[Topic]): void;
|
|
20
|
+
subscribe<Topic extends keyof Data>(topic: Topic, listener: PubSubListener<Data, Topic>): number;
|
|
21
|
+
unsubscribe(subId: number): void;
|
|
22
|
+
asyncIterator<Topic extends keyof Data>(topic: Topic): AsyncIterable<Data[Topic]>;
|
|
23
|
+
/** @important This method will be required starting next major release. */
|
|
24
|
+
dispose?(): void;
|
|
25
|
+
/** @important This method will be required starting next major release. */
|
|
26
|
+
[DisposableSymbols.dispose]?(): void;
|
|
27
|
+
}
|
|
28
|
+
type PubSubListener<Data extends TopicDataMap, Topic extends keyof Data> = (data: Data[Topic]) => void;
|
|
29
|
+
|
|
30
|
+
interface TransportEntry<Options extends Record<string, any> = Record<string, any>> {
|
|
31
|
+
kind: string;
|
|
32
|
+
subgraph: string;
|
|
33
|
+
location?: string;
|
|
34
|
+
headers?: [string, string][];
|
|
35
|
+
options?: Options;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type SchemaTransform<TContext = Record<any, string>> = (originalWrappingSchema: GraphQLSchema, subschemaConfig: SubschemaConfig<any, any, any, TContext>) => GraphQLSchema;
|
|
39
|
+
type RequestTransform<T = Record<string, any>, TContext = Record<any, string>> = (originalRequest: ExecutionRequest, delegationContext: DelegationContext<TContext>, transformationContext: T) => ExecutionRequest;
|
|
40
|
+
type ResultTransform<T = Record<string, any>, TContext = Record<any, string>> = (originalResult: ExecutionResult, delegationContext: DelegationContext<TContext>, transformationContext: T) => ExecutionResult;
|
|
41
|
+
interface Transform<T = any, TContext = Record<string, any>> {
|
|
42
|
+
transformSchema?: SchemaTransform<TContext>;
|
|
43
|
+
transformRequest?: RequestTransform<T, TContext>;
|
|
44
|
+
transformResult?: ResultTransform<T, TContext>;
|
|
45
|
+
}
|
|
46
|
+
interface DelegationContext<TContext = Record<string, any>> {
|
|
47
|
+
subschema: GraphQLSchema | SubschemaConfig<any, any, any, TContext>;
|
|
48
|
+
subschemaConfig?: SubschemaConfig<any, any, any, TContext>;
|
|
49
|
+
targetSchema: GraphQLSchema;
|
|
50
|
+
operation: OperationTypeNode;
|
|
51
|
+
fieldName: string;
|
|
52
|
+
args?: Record<string, any>;
|
|
53
|
+
context?: TContext;
|
|
54
|
+
info?: GraphQLResolveInfo;
|
|
55
|
+
returnType: GraphQLOutputType;
|
|
56
|
+
onLocatedError?: (originalError: GraphQLError) => GraphQLError;
|
|
57
|
+
rootValue?: any;
|
|
58
|
+
transforms: Array<Transform<any, TContext>>;
|
|
59
|
+
transformedSchema: GraphQLSchema;
|
|
60
|
+
skipTypeMerging: boolean;
|
|
61
|
+
}
|
|
62
|
+
type DelegationPlanBuilder = (schema: GraphQLSchema, sourceSubschema: Subschema<any, any, any, any>, variableValues: Record<string, any>, fragments: Record<string, FragmentDefinitionNode>, fieldNodes: FieldNode[], context?: any, info?: GraphQLResolveInfo) => Array<Map<Subschema, SelectionSetNode>>;
|
|
63
|
+
interface ICreateProxyingResolverOptions<TContext = Record<string, any>> {
|
|
64
|
+
subschemaConfig: SubschemaConfig<any, any, any, TContext>;
|
|
65
|
+
operation?: OperationTypeNode;
|
|
66
|
+
fieldName?: string;
|
|
67
|
+
}
|
|
68
|
+
type CreateProxyingResolverFn<TContext = Record<string, any>> = (options: ICreateProxyingResolverOptions<TContext>) => GraphQLFieldResolver<any, TContext>;
|
|
69
|
+
interface BatchingOptions<K = any, V = any, C = K> {
|
|
70
|
+
extensionsReducer?: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>;
|
|
71
|
+
dataLoaderOptions?: DataLoader.Options<K, V, C>;
|
|
72
|
+
}
|
|
73
|
+
interface SubschemaConfig<K = any, V = any, C = K, TContext = Record<string, any>> {
|
|
74
|
+
name?: string;
|
|
75
|
+
schema: GraphQLSchema;
|
|
76
|
+
createProxyingResolver?: CreateProxyingResolverFn<TContext>;
|
|
77
|
+
rootValue?: any;
|
|
78
|
+
transforms?: Array<Transform<any, TContext>>;
|
|
79
|
+
merge?: Record<string, MergedTypeConfig<any, any, TContext>>;
|
|
80
|
+
executor?: Executor<TContext>;
|
|
81
|
+
batch?: boolean;
|
|
82
|
+
batchingOptions?: BatchingOptions<K, V, C>;
|
|
83
|
+
}
|
|
84
|
+
interface MergedTypeConfig<K = any, V = any, TContext = Record<string, any>> extends MergedTypeEntryPoint<K, V, TContext> {
|
|
85
|
+
entryPoints?: Array<MergedTypeEntryPoint>;
|
|
86
|
+
fields?: Record<string, MergedFieldConfig>;
|
|
87
|
+
canonical?: boolean;
|
|
88
|
+
}
|
|
89
|
+
interface MergedTypeEntryPoint<K = any, V = any, TContext = Record<string, any>> extends MergedTypeResolverOptions<K, V> {
|
|
90
|
+
selectionSet?: string;
|
|
91
|
+
key?: (originalResult: any) => K | PromiseLike<K>;
|
|
92
|
+
resolve?: MergedTypeResolver<TContext>;
|
|
93
|
+
}
|
|
94
|
+
interface MergedTypeResolverOptions<K = any, V = any> {
|
|
95
|
+
fieldName?: string;
|
|
96
|
+
args?: (originalResult: any) => Record<string, any>;
|
|
97
|
+
argsFromKeys?: (keys: ReadonlyArray<K>) => Record<string, any>;
|
|
98
|
+
valuesFromResults?: (results: any, keys: ReadonlyArray<K>) => Array<V>;
|
|
99
|
+
dataLoaderOptions?: DataLoader.Options<K, V>;
|
|
100
|
+
}
|
|
101
|
+
interface MergedFieldConfig {
|
|
102
|
+
selectionSet?: string;
|
|
103
|
+
computed?: boolean;
|
|
104
|
+
canonical?: boolean;
|
|
105
|
+
provides?: SelectionSetNode;
|
|
106
|
+
}
|
|
107
|
+
type MergedTypeResolver<TContext = Record<string, any>> = (originalResult: any, context: TContext, info: GraphQLResolveInfo, subschema: Subschema<any, any, any, TContext>, selectionSet: SelectionSetNode, key: any | undefined, type: GraphQLOutputType) => any;
|
|
108
|
+
|
|
109
|
+
interface ISubschema<K = any, V = any, C = K, TContext = Record<string, any>> extends SubschemaConfig<K, V, C, TContext> {
|
|
110
|
+
transformedSchema: GraphQLSchema;
|
|
111
|
+
}
|
|
112
|
+
declare class Subschema<K = any, V = any, C = K, TContext = Record<string, any>> implements ISubschema<K, V, C, TContext> {
|
|
113
|
+
name?: string;
|
|
114
|
+
schema: GraphQLSchema;
|
|
115
|
+
executor?: Executor<TContext>;
|
|
116
|
+
batch?: boolean;
|
|
117
|
+
batchingOptions?: BatchingOptions<K, V, C>;
|
|
118
|
+
createProxyingResolver?: CreateProxyingResolverFn<TContext>;
|
|
119
|
+
transforms: Array<Transform<any, TContext>>;
|
|
120
|
+
private _transformedSchema;
|
|
121
|
+
merge?: Record<string, MergedTypeConfig<any, any, TContext>>;
|
|
122
|
+
constructor(config: SubschemaConfig<K, V, C, TContext>);
|
|
123
|
+
get transformedSchema(): GraphQLSchema;
|
|
124
|
+
set transformedSchema(value: GraphQLSchema);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
type Instrumentation$1 = {
|
|
128
|
+
/**
|
|
129
|
+
* Wrap each subgraph execution request. This can happen multiple time for the same graphql operation.
|
|
130
|
+
*/
|
|
131
|
+
subgraphExecute?: (payload: {
|
|
132
|
+
executionRequest: ExecutionRequest;
|
|
133
|
+
}, wrapped: () => MaybePromise<void>) => MaybePromise<void>;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
declare module 'graphql' {
|
|
137
|
+
interface GraphQLResolveInfo {
|
|
138
|
+
executionRequest?: ExecutionRequest;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
interface UnifiedGraphPlugin<TContext> {
|
|
142
|
+
onSubgraphExecute?: OnSubgraphExecuteHook<TContext>;
|
|
143
|
+
onDelegationPlan?: OnDelegationPlanHook<TContext>;
|
|
144
|
+
onDelegationStageExecute?: OnDelegationStageExecuteHook<TContext>;
|
|
145
|
+
}
|
|
146
|
+
type OnSubgraphExecuteHook<TContext = any> = (payload: OnSubgraphExecutePayload<TContext>) => MaybePromise$1<Maybe<OnSubgraphExecuteDoneHook | void>>;
|
|
147
|
+
interface OnSubgraphExecutePayload<TContext> {
|
|
148
|
+
subgraph: GraphQLSchema;
|
|
149
|
+
subgraphName: string;
|
|
150
|
+
transportEntry?: TransportEntry;
|
|
151
|
+
executionRequest: ExecutionRequest<any, TContext>;
|
|
152
|
+
setExecutionRequest(executionRequest: ExecutionRequest): void;
|
|
153
|
+
executor: Executor;
|
|
154
|
+
setExecutor(executor: Executor): void;
|
|
155
|
+
requestId?: string;
|
|
156
|
+
logger?: Logger;
|
|
157
|
+
}
|
|
158
|
+
interface OnSubgraphExecuteDonePayload {
|
|
159
|
+
result: AsyncIterable<ExecutionResult$1> | ExecutionResult$1;
|
|
160
|
+
setResult(result: AsyncIterable<ExecutionResult$1> | ExecutionResult$1): void;
|
|
161
|
+
}
|
|
162
|
+
type OnSubgraphExecuteDoneHook = (payload: OnSubgraphExecuteDonePayload) => MaybePromise$1<Maybe<OnSubgraphExecuteDoneResult | void>>;
|
|
163
|
+
type OnSubgraphExecuteDoneResultOnNext = (payload: OnSubgraphExecuteDoneOnNextPayload) => MaybePromise$1<void>;
|
|
164
|
+
interface OnSubgraphExecuteDoneOnNextPayload {
|
|
165
|
+
result: ExecutionResult$1;
|
|
166
|
+
setResult(result: ExecutionResult$1): void;
|
|
167
|
+
}
|
|
168
|
+
type OnSubgraphExecuteDoneResultOnEnd = () => MaybePromise$1<void>;
|
|
169
|
+
type OnSubgraphExecuteDoneResult = {
|
|
170
|
+
onNext?: OnSubgraphExecuteDoneResultOnNext;
|
|
171
|
+
onEnd?: OnSubgraphExecuteDoneResultOnEnd;
|
|
172
|
+
};
|
|
173
|
+
type OnDelegationPlanHook<TContext> = (payload: OnDelegationPlanHookPayload<TContext>) => Maybe<OnDelegationPlanDoneHook | void>;
|
|
174
|
+
interface OnDelegationPlanHookPayload<TContext> {
|
|
175
|
+
supergraph: GraphQLSchema;
|
|
176
|
+
subgraph: string;
|
|
177
|
+
sourceSubschema: Subschema<any, any, any, TContext>;
|
|
178
|
+
typeName: string;
|
|
179
|
+
variables: Record<string, any>;
|
|
180
|
+
fragments: Record<string, FragmentDefinitionNode>;
|
|
181
|
+
fieldNodes: SelectionNode[];
|
|
182
|
+
context: TContext;
|
|
183
|
+
requestId?: string;
|
|
184
|
+
logger?: Logger;
|
|
185
|
+
info?: GraphQLResolveInfo$1;
|
|
186
|
+
delegationPlanBuilder: DelegationPlanBuilder;
|
|
187
|
+
setDelegationPlanBuilder(delegationPlanBuilder: DelegationPlanBuilder): void;
|
|
188
|
+
}
|
|
189
|
+
type OnDelegationPlanDoneHook = (payload: OnDelegationPlanDonePayload) => Maybe<void>;
|
|
190
|
+
interface OnDelegationPlanDonePayload {
|
|
191
|
+
delegationPlan: ReturnType<DelegationPlanBuilder>;
|
|
192
|
+
setDelegationPlan: (delegationPlan: ReturnType<DelegationPlanBuilder>) => void;
|
|
193
|
+
}
|
|
194
|
+
type OnDelegationStageExecuteHook<TContext> = (payload: OnDelegationStageExecutePayload<TContext>) => Maybe<OnDelegationStageExecuteDoneHook>;
|
|
195
|
+
interface OnDelegationStageExecutePayload<TContext> {
|
|
196
|
+
object: any;
|
|
197
|
+
context: TContext;
|
|
198
|
+
info: GraphQLResolveInfo$1;
|
|
199
|
+
subgraph: string;
|
|
200
|
+
subschema: Subschema<any, any, any, TContext>;
|
|
201
|
+
selectionSet: SelectionSetNode;
|
|
202
|
+
key?: any;
|
|
203
|
+
type: GraphQLOutputType$1;
|
|
204
|
+
resolver: MergedTypeResolver<TContext>;
|
|
205
|
+
setResolver: (resolver: MergedTypeResolver<TContext>) => void;
|
|
206
|
+
typeName: string;
|
|
207
|
+
requestId?: string;
|
|
208
|
+
logger?: Logger;
|
|
209
|
+
}
|
|
210
|
+
type OnDelegationStageExecuteDoneHook = (payload: OnDelegationStageExecuteDonePayload) => void;
|
|
211
|
+
interface OnDelegationStageExecuteDonePayload {
|
|
212
|
+
result: any;
|
|
213
|
+
setResult: (result: any) => void;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
interface GatewayConfigContext {
|
|
217
|
+
/**
|
|
218
|
+
* WHATWG compatible Fetch implementation.
|
|
219
|
+
*/
|
|
220
|
+
fetch: MeshFetch;
|
|
221
|
+
/**
|
|
222
|
+
* The logger to use throught Mesh and it's plugins.
|
|
223
|
+
*/
|
|
224
|
+
logger: Logger;
|
|
225
|
+
/**
|
|
226
|
+
* Current working directory.
|
|
227
|
+
*/
|
|
228
|
+
cwd: string;
|
|
229
|
+
/**
|
|
230
|
+
* Event bus for pub/sub.
|
|
231
|
+
*/
|
|
232
|
+
pubsub?: HivePubSub;
|
|
233
|
+
/**
|
|
234
|
+
* Cache Storage
|
|
235
|
+
*/
|
|
236
|
+
cache?: KeyValueCache;
|
|
237
|
+
}
|
|
238
|
+
interface GatewayContext extends GatewayConfigContext, YogaInitialContext {
|
|
239
|
+
/**
|
|
240
|
+
* Environment agnostic HTTP headers provided with the request.
|
|
241
|
+
*/
|
|
242
|
+
headers: Record<string, string>;
|
|
243
|
+
/**
|
|
244
|
+
* Runtime context available within WebSocket connections.
|
|
245
|
+
*/
|
|
246
|
+
connectionParams: Record<string, string>;
|
|
247
|
+
}
|
|
248
|
+
type GatewayPlugin<TPluginContext extends Record<string, any> = Record<string, any>, TContext extends Record<string, any> = Record<string, any>> = Plugin<Partial<TPluginContext> & GatewayContext & TContext> & UnifiedGraphPlugin<Partial<TPluginContext> & GatewayContext & TContext> & {
|
|
249
|
+
onFetch?: OnFetchHook<Partial<TPluginContext> & GatewayContext & TContext>;
|
|
250
|
+
onCacheGet?: OnCacheGetHook;
|
|
251
|
+
onCacheSet?: OnCacheSetHook;
|
|
252
|
+
onCacheDelete?: OnCacheDeleteHook;
|
|
253
|
+
/**
|
|
254
|
+
* An Instrumentation instance that will wrap each phases of the request pipeline.
|
|
255
|
+
* This should be used primarily as an observability tool (for monitoring, tracing, etc...).
|
|
256
|
+
*
|
|
257
|
+
* Note: The wrapped functions in instrumentation should always be called. Use hooks to
|
|
258
|
+
* conditionally skip a phase.
|
|
259
|
+
*/
|
|
260
|
+
instrumentation?: Instrumentation<TPluginContext & TContext & GatewayContext>;
|
|
261
|
+
};
|
|
262
|
+
type OnCacheGetHook = (payload: OnCacheGetHookEventPayload) => MaybePromise$1<OnCacheGetHookResult | void>;
|
|
263
|
+
interface OnCacheGetHookEventPayload {
|
|
264
|
+
cache: KeyValueCache;
|
|
265
|
+
key: string;
|
|
266
|
+
ttl?: number;
|
|
267
|
+
}
|
|
268
|
+
interface OnCacheGetHookResult {
|
|
269
|
+
onCacheHit?: OnCacheHitHook;
|
|
270
|
+
onCacheMiss?: OnCacheMissHook;
|
|
271
|
+
onCacheGetError?: OnCacheErrorHook;
|
|
272
|
+
}
|
|
273
|
+
type OnCacheErrorHook = (payload: OnCacheErrorHookPayload) => void;
|
|
274
|
+
interface OnCacheErrorHookPayload {
|
|
275
|
+
error: Error;
|
|
276
|
+
}
|
|
277
|
+
type OnCacheHitHook = (payload: OnCacheHitHookEventPayload) => void;
|
|
278
|
+
interface OnCacheHitHookEventPayload {
|
|
279
|
+
value: any;
|
|
280
|
+
}
|
|
281
|
+
type OnCacheMissHook = () => void;
|
|
282
|
+
type OnCacheSetHook = (payload: OnCacheSetHookEventPayload) => MaybePromise$1<OnCacheSetHookResult | void>;
|
|
283
|
+
interface OnCacheSetHookResult {
|
|
284
|
+
onCacheSetDone?: () => void;
|
|
285
|
+
onCacheSetError?: OnCacheErrorHook;
|
|
286
|
+
}
|
|
287
|
+
interface OnCacheSetHookEventPayload {
|
|
288
|
+
cache: KeyValueCache;
|
|
289
|
+
key: string;
|
|
290
|
+
value: any;
|
|
291
|
+
ttl?: number;
|
|
292
|
+
}
|
|
293
|
+
type OnCacheDeleteHook = (payload: OnCacheDeleteHookEventPayload) => MaybePromise$1<OnCacheDeleteHookResult | void>;
|
|
294
|
+
interface OnCacheDeleteHookResult {
|
|
295
|
+
onCacheDeleteDone?: () => void;
|
|
296
|
+
onCacheDeleteError?: OnCacheErrorHook;
|
|
297
|
+
}
|
|
298
|
+
interface OnCacheDeleteHookEventPayload {
|
|
299
|
+
cache: KeyValueCache;
|
|
300
|
+
key: string;
|
|
301
|
+
}
|
|
302
|
+
type Instrumentation<TContext extends Record<string, any>> = Instrumentation$2<TContext> & Instrumentation$1 & FetchInstrumentation;
|
|
303
|
+
|
|
304
|
+
declare global {
|
|
305
|
+
var DEBUG: string;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
type JWTAuthPluginOptions = JwtPluginOptions & {
|
|
309
|
+
forward?: {
|
|
310
|
+
payload?: boolean | string;
|
|
311
|
+
token?: boolean | string;
|
|
312
|
+
extensionsFieldName?: string;
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* This Yoga plugin is used to extract the forwarded (from Mesh gateway) the JWT token and claims.
|
|
317
|
+
* Use this plugin in your Yoga server to extract the JWT token and claims from the forwarded extensions.
|
|
318
|
+
*/
|
|
319
|
+
declare function useForwardedJWT(config: {
|
|
320
|
+
extensionsFieldName?: string;
|
|
321
|
+
extendContextFieldName?: string;
|
|
322
|
+
}): Plugin<{
|
|
323
|
+
jwt?: JWTExtendContextFields;
|
|
324
|
+
}>;
|
|
325
|
+
/**
|
|
326
|
+
* This Mesh Gateway plugin is used to extract the JWT token and payload from the request and forward it to the subgraph.
|
|
327
|
+
*/
|
|
328
|
+
declare function useJWT(options: JWTAuthPluginOptions): GatewayPlugin<{
|
|
329
|
+
jwt?: JWTExtendContextFields;
|
|
330
|
+
}>;
|
|
331
|
+
|
|
332
|
+
export { type JWTAuthPluginOptions, useJWT as default, useForwardedJWT, useJWT };
|