amplify-codegen icon indicating copy to clipboard operation
amplify-codegen copied to clipboard

amplify codegen should auto compile schema before generating statements

Open chrisbonifacio opened this issue 2 years ago • 3 comments

How did you install the Amplify CLI?

yarn

If applicable, what version of Node.js are you using?

v18.14.2

Amplify CLI Version

11.0.5

What operating system are you using?

Mac (Apple Silicon)

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Describe the bug

Running amplify codegen on the latest version of the Amplify CLI is not resulting in new graphql statements in the src/graphql folder

running amplify api gql-compile before amplify codegen regenerates the statement files

Expected behavior

graphql statements should be updated with changes made to the local schema

Reproduction steps

  1. yarn global add @aws-amplify/[email protected]
  2. amplify init
  3. amplify add api-> GraphQL
  4. Edit local schema and add a new model
  5. amplify codegen add
  6. amplify codegen

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

chrisbonifacio avatar Apr 14 '23 17:04 chrisbonifacio

Closing as this was confirmed to be expected behavior. amplify api gql-compile must be run before amplify codegen to update the build schema with any changes to the local schema. The build schema is the input to amplify codegen, unlike amplify codegen models which uses the local schema.

chrisbonifacio avatar Apr 14 '23 17:04 chrisbonifacio

Converting this to a feature request. Would be a nice quality of life change to not have to run two commands to regenerate statements

chrisbonifacio avatar Apr 14 '23 17:04 chrisbonifacio

Closing as this was confirmed to be expected behavior. amplify api gql-compile must be run before amplify codegen to update the build schema with any changes to the local schema. The build schema is the input to amplify codegen, unlike amplify codegen models which uses the local schema.

The docs doesn't mention having to run amplify api gql-compile: https://docs.amplify.aws/cli/graphql/client-code-generation/

Is it supposed to be in the docs?

Also, I'm observing this behavior in my project:

  • If I do an amplify push, codegen does not pick up the latest schema changes. After amplify push is done, I have to run amplify codegen in order to get the latest changes.
  • I can also do an amplify api gql-compile then amplify codegen in order to get the latest changes without pushing first. This is based on this issue, and also the suggestion in #113 (this comment)

Is this by design? I thought amplify push will run codegen and pick up the latest changes, is this assumption correct?

Also, wouldn't this be a reasonable workflow? edit schema -> compile schema -> codegen -> git commit & push -> amplify push

Instead of the current one: edit schema -> amplify push -> codegen -> git commit & push

wpyoga avatar Jul 16 '23 17:07 wpyoga