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
87 stars 75 forks source link

Feature Request: Add Support for Renaming Snake Case Fields to Camel Case #2612

Open kekami opened 3 months ago

kekami commented 3 months ago

Describe the feature you'd like to request

I would like to request the addition of a feature in the Amplify Category API that allows for the automatic renaming of snake case fields to camel case when using a Postgres database to power the AppSync schema. This feature is particularly useful for developers who maintain consistency and readability in their GraphQL APIs, where camel case is often preferred for field names, while still adhering to the snake case convention commonly used in SQL databases such as Postgres. There are no existing issues or documentation that address this specific need, but it aligns with the general practice of improving developer experience and ensuring seamless integration between different layers of the application stack.

Describe the solution you'd like

The solution I envision would involve adding a configuration option to the Amplify CLI or within the defineData configuration that enables the automatic conversion of snake case fields in the database to camel case fields in the GraphQL API schema.

This could be implemented as follows: • Configuration Option: Introduce a configuration flag (e.g., renameSnakeToCamel) that can be set to true or false. • Automatic Conversion: When the flag is enabled, Amplify will automatically convert all snake case fields retrieved from the Postgres database to camel case in the generated AppSync schema. • Field Mapping: Ensure that the mapping between snake case fields in the database and camel case fields in the GraphQL schema is transparent and documented, possibly by generating a mapping file or including the mappings in the generated schema documentation. • Backward Compatibility: Provide a mechanism to opt-out or selectively apply this conversion to ensure backward compatibility for existing projects. This enhancement would significantly streamline the development process by reducing the need for manual field renaming and ensuring a consistent API surface for consumers of the GraphQL API.

This request aims to improve the developer experience by bridging the gap between SQL database conventions and GraphQL API best practices, making it easier to build and maintain robust applications.

Describe alternatives you've considered

None that I could think of.

Additional context

No response

Is this something that you'd be interested in working on?

Would this feature include a breaking change?

kekami commented 3 months ago

Just noticed that the docs mentions renameModelFields(). However the latest version of @aws-amplify/data-schema@1.3.1 does not have this method implemented.