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

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

Open arealmaas opened 3 years ago

arealmaas commented 3 years ago

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

ManasaYugensys commented 2 years ago

@phani-srikar any updates on this?

I am still getting error for union type

@arealmaas did you find any solution on this

ucheNkadiCode commented 1 year ago

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