Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to type(script) the event of a Serverless resolver sent from an Amplify GraphQL call #8

Open
jdanielsyeah opened this issue Oct 6, 2022 · 0 comments

Comments

@jdanielsyeah
Copy link

I am trying to type the event object coming from my AWS Amplify/NextJS front-end. It is sent via Amplify/GraphQL and being received in a NodeJS AWS Lambda. The typescript interface contained in import { AppSyncResolverEvent } from "aws-lambda"; - but this doesn't quite match the event object that's being received. Can someone please advise what I'm doing wrong?

Details:

I'm successfully firing an event from my front-end (NextJS) with aws-amplify and @aws-amplify/api-graphql packages:

import { graphqlOperation, GraphQLResult } from "@aws-amplify/api-graphql"; // "version": "2.3.11",
import { API } from "aws-amplify"; // "aws-amplify": "^4.3.28",

...
    // Retrieve schemas from Lambda
    const response = (await API.graphql<{ myAppSyncFunctionResponse: any }>(
      graphqlOperation(myAppSyncFunction),
      { input: "foo" }
    )) as GraphQLResult<{ myAppSyncFunctionResponse: string }>;

The event is being successfully received in my Serverless Lambda and resembles the following:

{
  typeName: "Mutation",
  fieldName: "myAppSyncFunction",
  arguments: { input: { ... } },
  identity: {...},
  source: ...,
  request: ...,
  prev:...
}

However, when I try to use aws-lambda in my nodejs Lambda environment:

import { AppSyncResolverEvent } from "aws-lambda";

export async function eventBridgeResolver(
  event: AppSyncResolverEvent
) {...}

AppSyncResolverEvent contains different properties:

// node_modules/@types/aws-lambda/trigger/appsync-resolver.d.ts
{
 arguments: TArguments;
    identity?: AppSyncIdentity;
    source: TSource;
    request: {
        headers: AppSyncResolverEventHeaders;
    };
    info: {
        selectionSetList: string[];
        selectionSetGraphQL: string;
        parentTypeName: string;
        fieldName: string;
        variables: { [key: string]: any };
    };
    prev: { result: { [key: string]: any } } | null;
    stash: { [key: string]: any };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant