aws-amplify / aws-amplify/amplify-codegen
Cannot generate Models from GraphQL schema
- Dominant language
- TypeScript
- Stars
- 59
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
### Amplify CLI Version
12.10.1
### Question
So I have [this schema](https://pastebin.com/VLcrTvsS) that I use in my [Amplify project on AWS](https://i.imgur.com/exOjwVF.png). This schema works perfectly fine when going through the motions of integrating Amplify into a project on iOS.
On Android however, there is an issue.
To reproduce this I do:
- `amplify pull --appId xxxxxxxx`
- `amplify pull`
- `amplify codegen`
This successfully generates the Queries, Mutations and Subscriptions under `graphql` folder with `schema.json` sitting in that folder.
At this stage the Models are not generated, the actual classes behind that schema, even though on iOS they are in that step above, on Android I have to do an extra step:
- `amplify codegen models`
And here is where the issue lies, I always get this exception when running that command to get my Models:
```
Error: Unknown type Vendor for field vendor. Did you forget to add the @model directive
at AppSyncModelJavaVisitor.getNativeType (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-visitor.js:220:19)
at AppSyncModelJavaVisitor.getNativeType (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:479:34)
at AppSyncModelJavaVisitor.generateModelField (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:239:32)
at /snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:149:18
at Array.forEach ()
at AppSyncModelJavaVisitor.generateModelClass (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:147:22)
at /snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:113:43
at Array.forEach ()
at AppSyncModelJavaVisitor.generateModelClasses (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:112:50)
at AppSyncModelJavaVisitor.generate (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/visitors/appsync-java-visitor.js:44:21)
at Object.plugin (/snapshot/amplify-cli/build/node_modules/@aws-amplify/appsync-modelgen-plugin/lib/plugin.js:55:24)
at /snapshot/amplify-cli/build/node_modules/@graphql-codegen/core/cjs/execute-plugin.js:36:54
at /snapshot/amplify-cli/build/node_modules/@graphql-codegen/core/node_modules/@graphql-codegen/plugin-helpers/cjs/profiler.js:7:49
```
I have a workaround wherein I replace `Vendor` and `Product` from `interface` to `type` and have them both implement a duplicate `inteface` instead, and in all occurrences of `implements Product` and `implements Vendor` I place `implements IProduct` and `implements IVendor`. This makes the codegen generate the Models successfully, but I don't want to have to do that.
What can I do to have this schema work as it should?
Is this schema AppSync comaptible?
If not, how can I convert it to be compatible and have this flow work as it should? Because remember, I still don't have the code for the Queries/Mutations/Subscriptions that are supposed to be using the generated Models, that still has to happen when I run my project and the `appsync gradle plugin` does its job (which it also fails for another reason).
What can I do?
Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.