UNPKG

3.36 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 type AppSyncIdentity =
34 | AppSyncIdentityIAM
35 | AppSyncIdentityCognito
36 | AppSyncIdentityOIDC
37 | AppSyncIdentityLambda
38 | undefined
39 | null;
40
41/**
42 * See https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html
43 *
44 * @param TArguments type of the arguments
45 * @param TSource type of the source
46 */
47// Maintainer's note: Some of these properties are shared with the Amplify resolver.
48// It may be worth checking if changes here may be applicable there too.
49export interface AppSyncResolverEvent<TArguments, TSource = Record<string, any> | null> {
50 arguments: TArguments;
51 identity?: AppSyncIdentity;
52 source: TSource;
53 request: {
54 headers: AppSyncResolverEventHeaders;
55 /** The API's custom domain if used for the request. */
56 domainName: string | null;
57 };
58 info: {
59 selectionSetList: string[];
60 selectionSetGraphQL: string;
61 parentTypeName: string;
62 fieldName: string;
63 variables: { [key: string]: any };
64 };
65 prev: { result: { [key: string]: any } } | null;
66 stash: { [key: string]: any };
67}
68
69export interface AppSyncAuthorizerEvent {
70 authorizationToken: string;
71 requestContext: {
72 apiId: string;
73 accountId: string;
74 requestId: string;
75 queryString: string;
76 variables: { [key: string]: any };
77 };
78}
79
80export interface AppSyncAuthorizerResult<TResolverContext = undefined> {
81 isAuthorized: boolean;
82 resolverContext?: TResolverContext;
83 deniedFields?: string[];
84 ttlOverride?: number;
85}
86export interface AppSyncIdentityIAM {
87 accountId: string;
88 cognitoIdentityPoolId: string;
89 cognitoIdentityId: string;
90 sourceIp: string[];
91 username: string;
92 userArn: string;
93 cognitoIdentityAuthType: string;
94 cognitoIdentityAuthProvider: string;
95}
96
97export interface AppSyncIdentityCognito {
98 sub: string;
99 issuer: string;
100 username: string;
101 claims: any;
102 sourceIp: string[];
103 defaultAuthStrategy: string;
104 groups: string[] | null;
105}
106
107export interface AppSyncIdentityOIDC {
108 claims: any;
109 issuer: string;
110 sub: string;
111}
112
113export interface AppSyncIdentityLambda {
114 resolverContext: any;
115}