Mock function not using mock API
See original GitHub issueNote: If your issue/bug is regarding the AWS Amplify Console service, please log it in the Amplify Console GitHub Issue Tracker
Describe the bug
When testing my lambda function via mock, the API_MYPROJECT_GRAPHQLAPIENDPOINTOUTPUT
environment variable points to amazonaws.com even though the mock api server is running.
Amplify CLI Version 4.41.1
To Reproduce
Terminal 1: amplify mock
Terminal 2: amplify status
Terminal 3: amplify mock function mylambda --event src/event.json --timeout 7
Expected behavior
amplify status should show the AppSync mock endpoint that’s running.
The API_MYPROJECT_GRAPHQLAPIENDPOINTOUTPUT
environment variable should point to the mock endpoint.
Desktop (please complete the following information):
- OS: Mac BigSur 11.1 Macbook Pro M1
- Node Version v14.12.0
Additional context The react app DOES correctly switch between the cloud and the mock endpoint. GraphiQL explorer runs on localhost.
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (3 by maintainers)
@m2broth Yes, my workaround it to overwrite the APIKEYOUTPUT variable when mock is running.
In
index.js
I add the following:Hope that helps.
(PS: If you’re also using a mock GraphQL, beware it behaves differently than production for queries that return non-nullable results: https://github.com/aws-amplify/amplify-cli/issues/6450)
@attilah Exactly correct.
I’d like to do all my testing locally. The webapp (react) is using the mocked graphql and S3. I have an amplify generated lambda function (a webhook that will be called by a 3rd party). When I mock test the function, it always writes data to the cloud instead of the local gql server.
I have 3 terminals, one in Visual Studio running the webapp, one running “amplify mock” for api & storage, and one to mock trigger the lambda function.
Thank you, I’m enjoying using Amplify very much.
-d-