@graphql-hive/plugin-aws-sigv4
Version:
143 lines (138 loc) • 4.71 kB
text/typescript
import { UnifiedGraphPlugin } from '@graphql-mesh/fusion-runtime';
import { Plugin, YogaInitialContext } from 'graphql-yoga';
import { MeshFetch, Logger, MeshPubSub, KeyValueCache, OnFetchHook } from '@graphql-mesh/types';
import { MaybePromise } from '@graphql-tools/utils';
interface GatewayConfigContext {
/**
* WHATWG compatible Fetch implementation.
*/
fetch: MeshFetch;
/**
* The logger to use throught Mesh and it's plugins.
*/
logger: Logger;
/**
* Current working directory.
*/
cwd: string;
/**
* Event bus for pub/sub.
*/
pubsub?: MeshPubSub;
/**
* Cache Storage
*/
cache?: KeyValueCache;
}
interface GatewayContext extends GatewayConfigContext, YogaInitialContext {
/**
* Environment agnostic HTTP headers provided with the request.
*/
headers: Record<string, string>;
/**
* Runtime context available within WebSocket connections.
*/
connectionParams: Record<string, string>;
}
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> & {
onFetch?: OnFetchHook<Partial<TPluginContext> & GatewayContext & TContext>;
onCacheGet?: OnCacheGetHook;
onCacheSet?: OnCacheSetHook;
onCacheDelete?: OnCacheDeleteHook;
} & Partial<Disposable | AsyncDisposable>;
type OnCacheGetHook = (payload: OnCacheGetHookEventPayload) => MaybePromise<OnCacheGetHookResult | void>;
interface OnCacheGetHookEventPayload {
cache: KeyValueCache;
key: string;
ttl?: number;
}
interface OnCacheGetHookResult {
onCacheHit?: OnCacheHitHook;
onCacheMiss?: OnCacheMissHook;
onCacheGetError?: OnCacheErrorHook;
}
type OnCacheErrorHook = (payload: OnCacheErrorHookPayload) => void;
interface OnCacheErrorHookPayload {
error: Error;
}
type OnCacheHitHook = (payload: OnCacheHitHookEventPayload) => void;
interface OnCacheHitHookEventPayload {
value: any;
}
type OnCacheMissHook = () => void;
type OnCacheSetHook = (payload: OnCacheSetHookEventPayload) => MaybePromise<OnCacheSetHookResult | void>;
interface OnCacheSetHookResult {
onCacheSetDone?: () => void;
onCacheSetError?: OnCacheErrorHook;
}
interface OnCacheSetHookEventPayload {
cache: KeyValueCache;
key: string;
value: any;
ttl?: number;
}
type OnCacheDeleteHook = (payload: OnCacheDeleteHookEventPayload) => MaybePromise<OnCacheDeleteHookResult | void>;
interface OnCacheDeleteHookResult {
onCacheDeleteDone?: () => void;
onCacheDeleteError?: OnCacheErrorHook;
}
interface OnCacheDeleteHookEventPayload {
cache: KeyValueCache;
key: string;
}
declare global {
var DEBUG: string;
}
interface AWSSignv4PluginOptions {
/**
* To sign the query instead of adding an Authorization header
* @default false
*/
signQuery?: boolean;
/**
* Service name to use when signing the request.
* By default, it is inferred from the hostname.
*/
serviceName?: string;
/**
* Region name to use when signing the request.
* By default, it is inferred from the hostname.
*/
region?: string;
/**
* ACCESS_KEY_ID
* @default process.env.AWS_ACCESS_KEY_ID || process.env.AWS_ACCESS_KEY
*/
accessKeyId?: string;
/**
* AWS_SECRET_ACCESS_KEY
* @default process.env.AWS_SECRET_ACCESS_KEY || process.env.AWS_SECRET_KEY
*/
secretAccessKey?: string;
/**
* AWS_SESSION_TOKEN
* @default process.env.AWS_SESSION_TOKEN
*/
sessionToken?: string;
/**
* An identifier for the assumed role session.
*
* @default process.env.AWS_ROLE_ARN
*/
roleArn?: string;
/**
* The Amazon Resource Names (ARNs) of the IAM managed policies that you want to use as
* managed session policies. The policies must exist in the same account as the role.
*
* @default process.env.AWS_IAM_ROLE_SESSION_NAME
*/
roleSessionName?: string;
}
interface AWSSignv4PluginOptionsFactoryOptions {
url: string;
options: RequestInit;
subgraphName: string;
}
type AWSSignv4PluginOptionsFactory = (factoryOptions: AWSSignv4PluginOptionsFactoryOptions) => AWSSignv4PluginOptions | undefined | false | true;
declare function useAWSSigv4<TContext extends Record<string, any>>(opts?: AWSSignv4PluginOptions | AWSSignv4PluginOptionsFactory): GatewayPlugin<TContext>;
export { type AWSSignv4PluginOptions, type AWSSignv4PluginOptionsFactory, type AWSSignv4PluginOptionsFactoryOptions, useAWSSigv4 };