Skip to content

Mocking a function that inserts data to AppSync result in Error: Must provide Source. Received: undefined #10573

@mstoyanovv

Description

@mstoyanovv

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v14.19.3

Amplify CLI Version

8.0.2

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

I have not

Amplify Categories

storage, function

Amplify Commands

Not applicable

Describe the bug

I am following the documentation for Calling GraphQL API from a Lambda function and everything works when deployed but I cannot mock it locally. First issue was that amplify mock does not support ES modules and therefore the examples in the documentation are not working with it. I fixed that by using node-fetch v2 which works with commonjs and switched to requiring modules so mocking would work.
Next issue is that the example code provided for mutation works when deployed in aws but does not work with amplify mock api and amplify mock function. The error returned by graphql local endpoint is "Must provide Source. Received: undefined".

Expected behavior

The examples provided in the documentation should work as expected when mocking locally and data should be inserted in the local graphql.

Reproduction steps

  1. Create function for graphql mutation following the example here)
  2. Modify code to use commonjs modules instead of ES ones so amplify mock function would work
  3. Execute amplify mock function with sample event

GraphQL schema(s)

# Put schemas below this line

Log output

# Put your logs below this line


Additional information

No response

Metadata

Metadata

Assignees

Labels

documentationAdd or update documentationfunctionsIssues tied to the functions categorymockIssues tied to the mock functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions