-
Notifications
You must be signed in to change notification settings - Fork 825
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
Mock function not using mock API #6384
Comments
@dmost714 just to make sure I understand correctly you have a Lambda that is configured to access the GraphQL API and when mock server is running you would like that The two 'mocks' are different processes as the invocations as well, but it seems to be a useful enhancement |
@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- |
Now that I understand this is an enhancement, I see the documentation talks about updating the web/mobile app config, but not the Lambda's config. To help anyone finding this thread before the enhancement is added... The environment variable will not be overwritten by prefixing it to the command: However, using a different environment variable is a perfectly acceptable workaround. And add this at the beginning of your lambda:
Thanks. |
Since our goal to make this low friction for developers we probably will want to provide an automated way to make this happen and an additional flag for mock function to disable this behavior. It is a bearable workaround I think, for now. |
This ticket is still open, but the behavior appears to have changed.
Hope the above helps. |
OK, did some regression testing and can confirm the behavior changed in CLI v4.44.0. Amplify CLI v4.41.0, 4.41.1, 4.41.2, 4.42.0, 4.43.0 all accept environment vars from the command line. They all issue a warning when I run in my environment to the effect of Starting with CLI v4.44.0, I no longer get the 'Could not find ref' warning when running v4.43.0 (LOCALENV:123456 found)
v4.44.0 (LOCALENV:123456 missing):
|
Just notice the new environment vars have my |
@dmost714 Hi, Have you found a workaround for how to solve this? Trying to find some automated way but it seems to be impossible now |
@m2broth Yes, my workaround it to overwrite the APIKEYOUTPUT variable when mock is running. In
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: #6450) |
@dmost714 Thanks. Implemented a similar temporary solution. |
@dmost714 thanks, that worked for me as a fix for now |
Hearing that is a nice start to my morning. If your lambda is a mock, but your GQL is in the cloud you won't want to replace the cloud key with the mock key. I'm now checking where the GQL endpoint is hosted to determine which key to use: |
I believe the API related environment variables are now being populated correctly by mock.
That behavior should be fixed now too. Please try with the latest version of the CLI. |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
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):
Additional context
The react app DOES correctly switch between the cloud and the mock endpoint.
GraphiQL explorer runs on localhost.
Thanks
The text was updated successfully, but these errors were encountered: