UNPKG

3.54 kBTypeScriptView Raw
1import { Handler } from "../handler";
2
3export type AppSyncResolverHandler<TArguments, TResult, TSource = Record<string, any> | null> = Handler<
4 AppSyncResolverEvent<TArguments, TSource>,
5 TResult
6>;
7
8// https:docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html#advanced-use-case-batching
9export type AppSyncBatchResolverHandler<TArguments, TResult, TSource = Record<string, any> | null> = Handler<
10 Array<AppSyncResolverEvent<TArguments, TSource>>,
11 TResult[]
12>;
13
14/**
15 * @deprecated Use {@link AppSyncAuthorizerHandler}
16 */
17export type AppSyncAuthorizerHander<TResolverContext = undefined> = AppSyncAuthorizerHandler<TResolverContext>;
18
19/**
20 * See https://docs.aws.amazon.com/appsync/latest/devguide/security-authz.html#aws-lambda-authorization
21 *
22 * @param TResolverContext type of the resolverContext object that you can return from the handler
23 */
24export type AppSyncAuthorizerHandler<TResolverContext = undefined> = Handler<
25 AppSyncAuthorizerEvent,
26 AppSyncAuthorizerResult<TResolverContext>
27>;
28
29export interface AppSyncResolverEventHeaders {
30 [name: string]: string | undefined;
31}
32
33export interface AppSyncAuthorizerEventHeaders {
34 [name: string]: string | undefined;
35}
36
37export type AppSyncIdentity =
38 | AppSyncIdentityIAM
39 | AppSyncIdentityCognito
40 | AppSyncIdentityOIDC
41 | AppSyncIdentityLambda
42 | undefined
43 | null;
44
45/**
46 * See https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html
47 *
48 * @param TArguments type of the arguments
49 * @param TSource type of the source
50 */
51// Maintainer's note: Some of these properties are shared with the Amplify resolver.
52// It may be worth checking if changes here may be applicable there too.
53export interface AppSyncResolverEvent<TArguments, TSource = Record<string, any> | null> {
54 arguments: TArguments;
55 identity?: AppSyncIdentity;
56 source: TSource;
57 request: {
58 headers: AppSyncResolverEventHeaders;
59 /** The API's custom domain if used for the request. */
60 domainName: string | null;
61 };
62 info: {
63 selectionSetList: string[];
64 selectionSetGraphQL: string;
65 parentTypeName: string;
66 fieldName: string;
67 variables: { [key: string]: any };
68 };
69 prev: { result: { [key: string]: any } } | null;
70 stash: { [key: string]: any };
71}
72
73export interface AppSyncAuthorizerEvent {
74 authorizationToken: string;
75 requestContext: {
76 apiId: string;
77 accountId: string;
78 requestId: string;
79 queryString: string;
80 operationName?: string;
81 variables: { [key: string]: any };
82 };
83 requestHeaders: AppSyncAuthorizerEventHeaders;
84}
85
86export interface AppSyncAuthorizerResult<TResolverContext = undefined> {
87 isAuthorized: boolean;
88 resolverContext?: TResolverContext;
89 deniedFields?: string[];
90 ttlOverride?: number;
91}
92export interface AppSyncIdentityIAM {
93 accountId: string;
94 cognitoIdentityPoolId: string;
95 cognitoIdentityId: string;
96 sourceIp: string[];
97 username: string;
98 userArn: string;
99 cognitoIdentityAuthType: string;
100 cognitoIdentityAuthProvider: string;
101}
102
103export interface AppSyncIdentityCognito {
104 sub: string;
105 issuer: string;
106 username: string;
107 claims: any;
108 sourceIp: string[];
109 defaultAuthStrategy: string;
110 groups: string[] | null;
111}
112
113export interface AppSyncIdentityOIDC {
114 claims: any;
115 issuer: string;
116 sub: string;
117}
118
119export interface AppSyncIdentityLambda {
120 resolverContext: any;
121}