-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Amplify codegen generating enums.js file in src/graphql folder #35
Comments
Currently the modelgen in amplify has the enum generation for javascript, which is executed by the command import { your_enum_name } from 'src/models' |
Thanks for this @AaronZyLee, didn't know about it. From my prospective, it would be still nice to export enums on the client's side, together with mutations, queries, and subs, just for the sake of automation. |
Hi @asmajlovicmars, thanks for this feature request. Enums are not native types in Javascript. But, we do generate enum definitions for Flow and Typescript language targets. To take advantage of that, you could update your codegen configuration using |
Thank you @phani-srikar. I thought having enums exported into a file would've been convenient. Will check this solution with flow. |
Hi @asmajlovicmars. I would like to know a little bit more about your use-case. If we had a schema like:
and
How would you use it in mutations, given that you're working on a JS project.
If it were a Typescript(or JS with Flow) project, we generate the enum types like:
which gives you more control over the values enum can accept. If you could tell me a bit more about how exposing the graphQL enum definitions in a JS project could benefit you, it would be really helpful to form a story around that which could help other developers. |
Hi @phani-srikar, my use case is even simpler than this, and it doesn't affect mutations... It's meant to prevent discrepancies between the front-end, and back-end enum definitions, so following your code, the front-end would collect enums from enums.js, parse the values, and for example populate the dropdown box... `
// ... populate a dropdown with categories ` |
Thanks a lot for your quick response @asmajlovicmars. Let me take this to my team and I will let you know any updates soon. |
Hi @asmajlovicmars. We had a discussion on this request and a similar one #44 . We will be able to support these use-cases with some of the re-design efforts we are working on. A RFC will soon be released and I would love to hear your comments on it. |
@asmajlovicmars - just wanted to let you know that we've publish an RFC to address this and other code generation issues. Would love to have your feedback! aws-amplify/amplify-cli#6898 |
Sorry to revive this zombie thread but I have the exact same use case as @asmajlovicmars. Reading the RFC I don't understand if the changes have already been implemented and if so, how to acutally get enums generated in js code for my frontend. Could you help? |
It appears these changes have not been implemented based on comments in the related issues. I'm marking both of these as feature requests. |
Problem:
Currently Amplify codegen generates GraphQL statements(queries, mutations and eventHandlers), but doesn't address the enums.
Quite often we define some "lookup" values in enums, which can change over time. When changes happen, updates have to be done on the both sides, back-end and front-end. This leads to potential discrepancies, and unnecessary work on both sides.
Solution:
The process of updating enums would be simplified and discrepancies avoided, by Amplify codegen generating an additional file beside queries, mutations, and subscriptions, called enums.js. That file would contain lookup values, which, once imported, would always provide updated values without a need to do any updates on the client side.
Developer Experience:
The text was updated successfully, but these errors were encountered: