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 76 forks source link

Amplify does not export enums to GraphQL schema properly from MySQL databases. #360

Open Ricardo1980 opened 4 years ago

Ricardo1980 commented 4 years ago

Describe the bug If the Aurora serverless data base has ENUM type, Amplify does not export that properly to the GraphQL schema. It just uses String! for those fields, instead of creating a graphql Enum.

To Reproduce Create a database with enum type, for example, use this in the CREATE TABLE script. state ENUM("pending", "live", "deactivated") NOT NULL Use amplify and select our aurora serverless data base with enums, using this command: "amplify api add-graphql-datasource"

Which AWS service(s) are affected? AWS Amplify CLI code generator

Expected behavior A GraphQL should be generated and that new type used in the appropriate field.

Environment(please complete the following information):

Device Information (please complete the following information):

**Additional info: Related bug: https://github.com/aws-amplify/aws-sdk-ios/issues/2106

jorge-rocksaucestudios commented 4 years ago

I found a bug related to the enum generation, it generates a new case without any reason

enum UserStatus { ... UNKNOWN ... }

Ricardo1980 commented 4 years ago

@jorge-rocksaucestudios That is normal. codegen adds automatically an extra enum with an associated value that is used when the enum cannot be mapped. Perhaps in the future you add a new state and old clients have to manage that. Using the (autogenerated) unknown state you can do it. What you have to do is to rename your own UNKNOW state and use any other name, then it will work. Evidently, the associated value is the new enum case that your app does not support at the moment.