aws-amplify / aws-amplify/amplify-codegen
Fail to generate models when union or interface types are used in the schema
- Dominant language
- TypeScript
- Stars
- 59
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
API, Typescript, Bug, Codegen models
**Describe the bug**
$ `amplify codegen models` fails to generate models when a union type or an interface is used in the graphql schema.
Amplify CLI Version: amplify -v: 4.45.1
Platform target: web
**To Reproduce:**
``` graphql
union Todo = XTodo | YTodo
type XTodo @model {
id: ID!
title: String!
}
type YTodo @model {
id: ID!
title: String!
status: String!
}
type Profile {
id: ID!
todos: [Todo] @function(name: "resolvers-${env}") # function that resolves the correct todo type
}
```
When using `amplify codegen models` I get the following error:
`Error: Unknown type Todo for field todos. Did you forget to add the @model directive`
**Expected behavior**
I expected to get models successfully generated. I cannot both use union/interface types in my schema and generate typescript-models, as no models will be generated because of this error. To fully utilize amplify I want to be able to generate the typescript models as well.
To circumvent the fact that Amplify doesn't support interface/unions I added a function resolver to resolve the correct type as was suggested in an issue somewhere. But now I'm having issues with the codegen. Could you please let this case go as a warning instead of an error, or fix the types for union/interface? 🤔
Contributor guide
Assessment
This issue has not been assessed yet.