amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

[Feature Request] Support `amplify mock api`

Open afnx opened this issue 2 years ago • 8 comments

Updated Description

Updated 05/02/2024 by @Jordan-Nelson

Amplify Flutter does not support amplify mock api. This issue will be used to track interest in this feature request.

Original Description

I can't establish a connection between my app and the local server:
amplify mock api

The local mock server starts like this and I'm able query the dynamodb from my lambda functions:

Mock does not handle CloudFormation resource of type AWS::IAM::ManagedPolicy. Skipping processing resource.
Running GraphQL codegen
Failed to run GraphQL codegen with following error:
Flutter only supports the command $amplify codegen models. All the other codegen commands are not supported.
AppSync Mock endpoint is running at http://localhost:20002

However, I get this error on the Flutter side when I launch the app even though I followed the instructions here:

Exception has occurred.
ConfigurationError (ConfigurationError {
  "message": "Non-HTTPS endpoint found for test_app which is not supported.",
  "recoverySuggestion": "Ensure the configured endpoint for test_app utilizes https."
})

Here's how I configure Amplify on Flutter:

if (!Amplify.isConfigured) {
  await Amplify.addPlugins([
    AmplifyAuthCognito(),
    AmplifyDataStore(modelProvider: ModelProvider.instance),
    AmplifyAPI(),
  ]);

  await Amplify.configure(amplifyconfig);

  debugPrint('Amplify configured successfully.');
} else {
  debugPrint('Amplify is already configured.');
}

All amplify libraries I'm using are up-to-date.

afnx avatar Nov 21 '23 07:11 afnx

The code that causes the issue:

https://github.com/aws-amplify/amplify-flutter/blob/ddafa9a1956303946f91d34cb857732dbeaae17f/packages/api/amplify_api_dart/lib/src/api_plugin_impl.dart#L82C1-L90C6

So, we want to make sure the connection uses https, but it's currently blocking us from connecting to the mock server. Is there a way we can first check if it's not a mock server before verifying the endpoint?

Maybe an additional parameter mockEnabled?

if(!entry.value.mockEnabled && !entry.value.endpoint.startsWith('https')) {
  // Throw configuration error
}

afnx avatar Nov 22 '23 02:11 afnx

I am adding my comment on here to get this prioritised.

Mocking Amplify DataStore using Mockito for Flutter

theartofnonso avatar Jan 25 '24 18:01 theartofnonso

@afnx @theartofnonso thanks for reporting this, We look into this and get back to you when we have updates. @theartofnonso do you use Amplify DataStore only or do you use Amplify DataStore with Amplify API to sync with cloud?

NikaHsn avatar Jan 25 '24 20:01 NikaHsn

@afnx This appears to have been a documentation issue, which has since been fixed.

haverchuck avatar Feb 02 '24 22:02 haverchuck

@NikaHsn I use Datastore alongside API to sync to cloud

theartofnonso avatar Feb 03 '24 12:02 theartofnonso

Any updates on this?

jmartins-sh avatar Mar 01 '24 18:03 jmartins-sh

hi, any update?

ImanGharib avatar Jun 16 '24 20:06 ImanGharib

Hi everyone,

I've implemented a new feature for Amplify CLI, https://github.com/aws-amplify/amplify-cli/pull/13700. You can now enable HTTPS on your mock server! With HTTPS enabled, this error goes away. Your Flutter application will be able to communicate with your test environment.

Upgrade your CLI version and simply use amplify mock api --https /path/to/key /path/to/cert.

afnx avatar Jun 16 '24 23:06 afnx