aws / aws/aws-appsync-community
Inconsistent types in lambda for JS resolvers
- Dominant language
- HTML
- Stars
- 507
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
Hello !
In JS Appsync resolvers, Lambda request object allows as much context information as possible to pass to the Lambda function, with the payload property.
```
type LambdaRequest = {
operation: 'Invoke' | 'BatchInvoke';
payload: any;
};
```
However, when using typescript for the actual Lambda function acting as my datasource, I pass the type AppSyncResolverHandler to my handler : (MutationUpdateUsernameArgs and BasicResponse are generated by my graphql schema)
```
export const handler: AppSyncResolverHandler<
MutationUpdateUsernameArgs,
BasicResponse
> = async (event) => {
// Code here
};
```
The event has therefore this type :
```
export interface AppSyncResolverEvent | null> {
arguments: TArguments;
identity?: AppSyncIdentity;
source: TSource;
request: {
headers: AppSyncResolverEventHeaders;
/** The API's custom domain if used for the request. */
domainName: string | null;
};
info: {
selectionSetList: string[];
selectionSetGraphQL: string;
parentTypeName: string;
fieldName: string;
variables: { [key: string]: any };
};
prev: { result: { [key: string]: any } } | null;
stash: { [key: string]: any };
}
```
When I try to access my event's payload properties, typescript tells me that those properties don't exist on the AppSyncResolverEvent.
Is this expected behaviour, am I doing something wrong?
Thank you for your help :)
Contributor guide
Research direction
No repository files or tests are named. Start by comparing the LambdaRequest and AppSyncResolverEvent examples, then trace the TypeScript resolver type definitions; done means the relationship between the payload and handler event type is clarified and the relevant behavior is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100