aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.3k stars 239 forks source link

[Feature Request] Support `amplify mock api` #4163

Open afnx opened 7 months ago

afnx commented 7 months ago

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: ```console 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](https://docs.amplify.aws/flutter/tools/cli/usage/mock/#ios-config): ```console 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: ```dart 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 commented 7 months ago

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
}
theartofnonso commented 5 months ago

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

Mocking Amplify DataStore using Mockito for Flutter

NikaHsn commented 5 months ago

@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?

haverchuck commented 5 months ago

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

theartofnonso commented 5 months ago

@NikaHsn I use Datastore alongside API to sync to cloud

jmartins-sh commented 4 months ago

Any updates on this?

ImanGharib commented 3 weeks ago

hi, any update?

afnx commented 3 weeks ago

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.