aws-amplify / aws-amplify/amplify-codegen

Amplify Codegen does not generate output in a consistent/deterministic order

Open
#167 5 comments 1 reaction 1 assignee Claimed by @AaronZyLee View on GitHub
bug model-gen p3 type-gen
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

First of all, I'm surprised I couldn't find an existing bug, so if I've missed it, apologies. But as I couldn't find one I'm creating this ticket as as surely I'm not the only one this drives nuts over time...

**Describe the bug**
Running `amplify push` and regenerating GraphQL code bindings, or simply running `amplify codegen` on a GraphQL schema that hasn't changed results in unnecessary changes to files such as `graphql/schema.json` simply due to reordering of the same output due to apparent non-deterministic ordering in the generated code.

**Amplify CLI Version**
4.35.0

**To Reproduce**
Run the commands listed above a few times and see unnecessary and noisy changes made to files such as `graphql/schema.json`.

**Expected behavior**
All code generated should be generated in a consistent deterministic, possibly sorted, order so that:

1. It is clear that a change in the generated file is caused by a change to the GraphQL schema that has just been pushed up, rather than changes in generated files unrelated to the schema change.
1. Currently I have to either spend a lot of time eyeballing the diffs to and reverting hunks if I'm absolutely sure something didn't change, or otherwise include it in file history just to be safe.
2. This is especially true because updating the `@aws-amplify/cli` package can cause expected changes to the generated files that are required even if not caused directly by user changes to their GraphQL schema, and so running a codegen after updating the package version without any GraphQL schema changes should be able to show if the version has introduced changes or not; currently that's not clear, it could just be non-deterministic reordering.
2. Git Commit history is not polluted with a ton of unnecessary changes making it hard to browse file history.

**Screenshots**
An example diff highlighting one such apparently unnecessary reordering:

amplify-codegen-reordering

**Desktop (please complete the following information):**
- OS: macOS 11.0.1
- Node Version: 15.2.0

**Additional context**
Git commit history is important to in order to understand when particular bugs may have been introduced and by what changes, and so unnecessary noise in codegen files is more important than it may seem.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.