-
Notifications
You must be signed in to change notification settings - Fork 822
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
Mocking a function that inserts data to AppSync result in Error: Must provide Source. Received: undefined #10573
Comments
Hey @mstoyanovv 👋 thanks for raising this, and apologies for the confusion with the ESM example & mock (support for this is tracked here #10432). Regardless of the outcome here I think we should include a CommonJS example on our docs as well. Would you be open to contributing to our docs examples with your CommonJS port? Can you confirm the API call is sending a valid body with the query/mutation and inputs when mocking? And to clarify, are the environment variables such as the GraphQL API endpoint being populated? |
Hey @josefaidt I will open a pr with commonjs samples. Regarding the body value I am sure that it is valid as it is the same when uploaded to aws via amplify function push. There it connects to appsync api and successfully inserts data. I also thought about the env variables and upon checking them they seem to be good. There is a graphql endpoint that points to localhost:20002/graphql and test api key variable that is not empty. |
Hey @josefaidt, I am also running into this. Running the local amplify mock, here's a sample payload for
And the same payload after it was signed:
As described in the original issue, deploying this exact same code and executing in the cloud from AppSync works just fine. Executing the same code locally with amplify mock gives me the "must provide source" error.
Thank you so much & let me know if you need any further info! |
^ Verified that the above is still the case with the latest CLI version: @aws-amplify/[email protected] |
Hey @myartsev and @mstoyanovv 👋 I was able to successfully reproduce this issue using a simple query to the mocked GraphQL API, and was able to mitigate it by adding the following header to the request, |
Adding pending-close per docs PR merge |
Closing, @mstoyanovv if you continue to experience issues after this small adjustment to the template please reply back to this thread and we can re-open to investigate further 🙂 |
Pr to update doc - aws-amplify/docs#4441 |
Before opening, please confirm:
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
GraphQL schema(s)
# Put schemas below this line
Log output
Additional information
No response
The text was updated successfully, but these errors were encountered: