aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

Inconsistent types in lambda for JS resolvers #288

Open oyatrides opened 1 year ago

oyatrides commented 1 year ago

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<TArguments, TSource = Record<string, any> | 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 :)