aws-amplify / amplify-codegen

Amplify Codegen is a JavaScript toolkit library for frontend and mobile developers building Amplify applications.
Apache License 2.0
60 stars 63 forks source link

cannot run amplify codegen #137

Closed rodrigobastosv closed 3 years ago

rodrigobastosv commented 3 years ago

Describe the bug I'm following the https://docs.amplify.aws/lib/datastore/getting-started/q/platform/flutter docs to implement DataStore on my flutter app. Doing Auth and Storage was just a breeze. But when trying to implement the DataStore i got an error on the codegen step

After creating a new graphql api and try to run amplify codegen models i got this error:

amplify-codegen-appsync-model-plugin not support language target flutter. Supported codegen targets arr java, android, swift, ios, javascript, typescript
Error: amplify-codegen-appsync-model-plugin not support language target flutter. Supported codegen targets arr java, android, swift, ios, javascript, typescript
    at Object.buildGeneratesSection (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-codegen-appsync-model-plugin/src/preset.ts:214:15)
    at Object.generateModels (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-codegen/src/commands/models.js:44:67)
    at Object.run (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-codegen/commands/codegen/models.js:9:7)
    at Object.executeAmplifyCommand (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-codegen/src/amplify-plugin-index.js:9:3)
    at executePluginModuleCommand (/usr/lib/node_modules/@aws-amplify/cli/src/execution-manager.ts:161:3)
    at Object.executeCommand (/usr/lib/node_modules/@aws-amplify/cli/src/execution-manager.ts:25:5)
    at Object.run (/usr/lib/node_modules/@aws-amplify/cli/src/index.ts:92:5)

After some digging some tutorials advise to use the amplify add codegen command. But when i do i got the error:

flutter is not supported by codegen plugin

I'm a bit newbie with amplify and i'm feeling a bit lost.

Platform Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply): [x] Android

jamesonwilliams commented 3 years ago

My guess is that you need to update your CLI. Codegen for Dart was only recently added to the CLI.

What version are you using? The latest version is 4.41.0.

$ amplify -v
4.41.0
rodrigobastosv commented 3 years ago

Thanks @jamesonwilliams , that works!

liamross commented 3 years ago

I'm still having this issue:

$ amplify upgrade
This is the latest Amplify CLI version.
$ amplify -v
4.41.0
$ amplify add codegen
flutter is not supported by codegen plugin
$ amplify add codegen --apiId xxxxxxxxxx
✔ Getting API details
Successfully added API YourAppSync to your Amplify project
flutter is not supported by codegen plugin
pedrommarquesm commented 3 years ago

no news on this? version 4.44.0 out and I also have this problem

Amplifiyer commented 3 years ago

@liamross, @pedrommarquesm can you try this workaround mentioned here https://github.com/aws-amplify/amplify-flutter/issues/241#issuecomment-755565445

pedrommarquesm commented 3 years ago

@Amplifiyer My project is recent, that flag is set by default on amplify init

hyobbb commented 3 years ago

after updating amplify-cli with npm i -g @aws-amplify/cli

solved problem.

raywhiteside commented 3 years ago

I am struggling to get this to work still. I have updated the Amplify CLI to 4.44.2, and amplify_flutter is at 0.1.0. I am trying to do the workaround in cli.json, but I can't find that file in my amplify folder in this old project. I ran amplify init again and told it to re-use the current workspace, but I still don't see the cli.json.

I should say I can run amplify codegen models, but I'm seeing this issue:

lib/models/ModelProvider.dart:23:7: Error: The non-abstract class 'ModelProvider' is missing implementations for these members:

 - ModelProviderInterface.getModelTypeByModelName

which seems to imply I don't have this commit from amplify-codegen from December:

https://github.com/aws-amplify/amplify-codegen/commit/b3daebb5b1425ca51fe6f85ff671960d6696510a

If I try to run amplify codegen add, I get the same "flutter is not supported" error which makes me think this ticket is relevant.

hyobbb commented 3 years ago

@raywhiteside if codeine is running in new version it should generate ModelProvider class overriding getModelTypeByModelName method. I had the same problem so I remove the project and start it over. aws-amplify/amplify-flutter#243 check this page.

raywhiteside commented 3 years ago

I copied my amplify folder and amplifyconfiguration.dart files to a different name, deleted the current versions, ran amplify init, and copied the new versions as well. Then I put the originals back and moved cli.json from the new amplify directory into the old one. Codegen now worked and I seemed to be synced up with my previous resources without issue after amplify push.

Wouldn't recommend trying to save the old space and I'm sure it will bite me at some point, but does work for now.

raywhiteside commented 3 years ago

Okay maybe this has bit me already. I'm trying to mock the API as described here and here, and the amplify mock command runs amplify codegen. That fails with the same error as the OP:

flutter is not supported by codegen plugin

Which is the same error I get if I run amplify codegen myself. I can run amplify codegen models and it generates functional code (unlike when I posted earlier in this issue) and that has been sufficient for me thus far, but is seems I need more than a workaround now. amplify codegen itself needs to work.

I'm running version 4.45.2 of the Amplify CLI.

Is amplify codegen working for anyone on flutter?

pedrommarquesm commented 3 years ago

@raywhiteside That's exactly what happens to me. I just don't get it how some people in other open issues, say their problem is solved with updating the CLI... a final answer to this would be cool

NKoroloff commented 3 years ago

I have some problem. flutter is not supported by codegen plugin

DavidTraina commented 3 years ago

Same problem here on fresh flutter project and amplify cli 4.46.1: flutter is not supported by codegen plugin

Amplifiyer commented 3 years ago

Assigning to amplify codegen team to take a look

AaronZyLee commented 3 years ago

Currently there are two kinds of codegen in amplify. One is the model generation for Datastore(high level), the other is the type/doc generation for appsycn users(low level). Accordingly, the codegen commands differ when it comes to the two scenario above. Datastore codegen commands:

$ amplify codegen models

Appsync codegen commands:

$ amplify codegen
$ amplify codegen add
$ amplify codegen configure
$ amplify codegen remove

AFAIK flutter libraries only supports the first one(Datastore). The amplify mock is also for the second use cases. That's why if you have a flutter project and you run the commands intended for the second scenario will fail. We also do not have the flutter use cases in the doc of low-level codegen commands and mock api.

TL;DR, you can only use amplify codegen models in a flutter project and you don't need amplify codegen/add before running model-gen command.

raywhiteside commented 3 years ago

Thanks for the detailed background @AaronZyLee.

I am still a bit confused on where the line is between Amplify CLI and Amplify Flutter. The amplify mock guide here is under Amplify CLI, which is separate from the Amplify Libraries section that has options for Flutter/Android/iOS/Javascript. Furthermore it's not obvious from the amplify mock guide that any of the commands are specific to certain libraries. In fact the goal is to locally mock backend AWS resources like AppSync and S3 - so it's not clear why this has any dependency on the frontend library such as Amplify Flutter. I'm not saying there is no good reason for such a dependency, only that the dependency is neither documented nor intuitively obvious to me.

In my mind we are getting away from the original issue now and there are two new topics cropping up:

  1. Can amplify mock and any other Amplify CLI flows that depend on low-level codegen commands be supported for Flutter? I'm not going to belabor this point, these flows are clearly useful and the request is parity.

  2. Until or in place of 1. being resolved, can the documentation and error messages be improved? Besides your response on this thread, the situation here is not only non-functional but confusing. flutter is not supported by codegen plugin is definitely helpful, but being required and able to run flutter codegen models is very strange. Changing the error message to something like:

flutter is only supported for "amplify codegen models", all other amplify codegen commands and flows that depend on them are not supported

This would have saved me a lot of time.

AaronZyLee commented 3 years ago

@raywhiteside Thanks for point this out.

For the first point, I contact the flutter team and they plan to support this feature on their roadmap, aka sending raw graphql request and amplify mock since this is a good workflow and requested feature by other developers. In addition, datastore does not use mock since it already has a local storage engine.

For the second, I agree that the error messaging is confusing and non-functional. I will fix this ASAP.