aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 77 forks source link

generate queries for interfaces #280

Open tobiasfeil opened 4 years ago

tobiasfeil commented 4 years ago

I'm currently modeling a scenario in this way:

interface Person {
    id: ID!
}

type Student implements Person @model {
    id: ID!
}

type StaffMember implements Person @model {
    id: ID!
}

I would like to be able to call getPerson from the frontend, and then handle the data depending on the type name.

An alternative approach that would also solve my problem would be to enable this behavior for unions.

AaronZyLee commented 3 years ago

Not really a codegen issue for now. The graphql operation doc is generated based on output of transformer. getXXX queries are auto-generated by @model in graphql-transformer, from which there is a limitation that it cannot be used on an interface for now. One possible solution is that the model directive(or a new directive for interface) will add get queries for the related interface. FYI there is an ongoing RFC for transformer V2 here: aws-amplify/amplify-cli#6217