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

Fail to generate models when union or interface types are used in the schema

Open arealmaas opened this issue 3 years ago • 13 comments

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:


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

arealmaas avatar Apr 07 '21 08:04 arealmaas

@phani-srikar any updates on this?

I am still getting error for union type

@arealmaas did you find any solution on this

ManasaYugensys avatar Jul 26 '22 12:07 ManasaYugensys

Would love for y'all to create this functionality. It would seriously simply my scenarios in the future

ucheNkadiCode avatar Dec 11 '22 12:12 ucheNkadiCode