Skip to content
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

[request?] amplify codegen does not reflect updated schema from local copy #113

Closed
swyxio opened this issue Jul 20, 2020 · 19 comments
Closed
Assignees
Labels
amplify-codegen Issues on amplify-codegen

Comments

@swyxio
Copy link
Contributor

swyxio commented Jul 20, 2020

Is your feature request related to a problem? Please describe.

Problem 1: codegen doesnt codegen from local copy

when i update my local schema in /amplify/backend/api/MYAPI/schema.graphql and run amplify codegen, the generated code in src/graphql doesn't update at all.

we are not sure if this is a bug or working as intended. but it's clear that in order to update the generated code i have to amplify push.

Problem 2: CLI gives the impression that codegen is done before push

I have to amplify push before i can codegen the new model:

image

this causes a LONG wait time and completely breaks my flow, for information i already have on my machine.

I ran amplify push 40 minutes 1 hour ago and am still waiting for my updated graphql schema so i can continue working. this is not a sustainable workflow when i'm just changing one little field on my schema.

Repro steps

  1. amplify add api
  2. amplify codegen
  3. change one field in the graphql schema
  4. amplify codegen again
  5. observe that nothing has changed in src/graphql

Describe the solution you'd like

i understand you do this in order to always codegen the right thing. but perhaps offer to codegen based off my local model first, if i accept the risks of mismatch between the model i have on my machine and the model i have in the cloud.

Describe alternatives you've considered

do nothing

@swyxio swyxio changed the title [request?] can amplify push run codegen before updating cloudformation to reduce super long wait time [request?] amplify codegen does not reflect updated schema Jul 20, 2020
@swyxio swyxio changed the title [request?] amplify codegen does not reflect updated schema [request?] amplify codegen does not reflect updated schema from local copy Jul 20, 2020
@AaronZyLee
Copy link
Contributor

The main reason for this is that the new schema is not compiled. A temporary solution is to run amplify api gql-compile after changing the schema and then it is all good to run amplify codegen. I will soon create a PR for graphql compiling check when running codegen.

@pagameba
Copy link

If I run the indicated commands, it still doesn't seem to update the generated code in src/graphql although the compile step does seem to know about the changes - just codegen doesn't do anything as far as I can tell.

@SwaySway
Copy link
Contributor

Re-opening as we are reconsidering the implementation. As of now the current workaround when making schema changes, you can run amplify api gql-compile && amplify codegen.

@SwaySway SwaySway reopened this Oct 26, 2020
@binadamu-isiyoonekana
Copy link

@SwaySway Hi Josue. Any progress on this subject, as with latest version of Amplify (namely 4.41.0), nothing is generated/updated in src/graphql folder (i.e mutations, queries, ...) when entering amplify api gql-compile && amplify codegen. Thanks and Happy New Year !

@SwaySway
Copy link
Contributor

@binadamu-isiyoonekana
Could you provide your .graphqlconfig.yml and the schema? If the schema contains sensitive information you can send it to our email amplify-cli@amazon.com

@vincent38wargnier
Copy link

vincent38wargnier commented Feb 27, 2021

I have exactly the same issue. I'm using codegen for months, and suddenly today it's not generating the code even if it's saying it's doing it :
image
And the Schema is well updated :
image

This is the graphql code I added to the API :

type NewsLetterSubscribers @model @auth(rules: [
  {allow: private, operations: [create]}
  {allow: public, operations: [create], provider: iam}
  {allow: public, operations: [read, update, create], provider: apiKey}
  ]) {
    id: ID!
    subscribed: Boolean!
    email: String!
    dateUnsubscribed: AWSDateTime
    reasonUnsubscribed: String
}

I have CLI version 4.44.0 on macOS

@vincent38wargnier
Copy link

vincent38wargnier commented Feb 28, 2021

I made some tries with the mock, creating news tables, and looking at the same time what is happening in the mutation.js file.

It happens that at some point during the code génération the code of the new tables is created, but it's removed right away, I don't know why.

At this point the new code is created :
image
And at this point its removed :
image

This is all the things I have in my console :
image
So first line creates the code, and the second indentical line removes it. I don't know what to understand from that. It seems that an instance of the API is stucked in the codegen system, so the codegen does its work properly, and then the old instance does its work as well, so the code generated at the end is related to the API before the bug appeared.

But apparently removing the .graphqlconfig.yml file solves the pb. Thanks to aws-amplify/amplify-cli#50 (comment)

Btw removing, or reinstalling codegen didn't change anything

@nubpro
Copy link

nubpro commented Mar 10, 2021

Re-opening as we are reconsidering the implementation. As of now the current workaround when making schema changes, you can run amplify api gql-compile && amplify codegen.

This workaround you proposed does not seems to work.
src/graphql doesnt get updated after running the command you suggested, however schema.json is. Tested on 4.44.0

.graphqlconfig.yml

projects:
  amplifyreact1:
    schemaPath: src/graphql/schema.json
    includes:
      - src/graphql/**/*.js
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: javascript
        generatedFileName: ''
        docsFilePath: src/graphql
        maxDepth: 2
extensions:
  amplify:
    version: 3

schema tested:

type Todo @model {
  id: ID!
  name: String!
  description: String
  test6: String <--- change this field name
}

@nubpro
Copy link

nubpro commented Mar 10, 2021

A little update:
I deleted my .graphqlconfig.yml and did amplify codegen add, it generated a new .graphqlconfig.yml with the following content:

projects:
  amplifyreact1:
    schemaPath: amplify/backend/api/amplifyreact1/build/schema.graphql
    includes:
      - src/graphql/**/*.js
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: javascript
        generatedFileName: ''
        docsFilePath: src/graphql
        region: ap-southeast-1
        apiId: null
        maxDepth: 2
extensions:
  amplify:
    version: 3

Noticed that schemaPath changed and inclusions of several new settings.

Afterwards, I ran amplify api gql-compile && amplify codegen, it now works as expected.
Is there a reason as to why this had happened?

@siegerts
Copy link
Contributor

siegerts commented Mar 16, 2021

Hi All, Thanks for keeping this updated and re-raising 🙌🏻 .

The team is looking into this now to determine the best path forward, and will update this as soon as there is more information.

Just an fyi - this will be transferred over to the amplify-codegen repo for better tracking (once permissions are set).

Thanks again!

@ankitmhn
Copy link

Is there a fix or some workaround for this? I'm still facing this issue.

@nubpro
Copy link

nubpro commented Apr 22, 2021

Is there a fix or some workaround for this? I'm still facing this issue.

#113 (comment)

@phani-srikar
Copy link
Contributor

The workaround is to re-compile your updated schema as mentioned here: #113 (comment)

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Jun 18, 2021

This issue has been automatically closed because of inactivity. Please open a new issue if you are still encountering problems.

@stale stale bot closed this as completed Jun 18, 2021
@Robbie-Cook
Copy link

Why in the name of all that is holy, do I need to use amplify api gql-compile && amplify codegen instead of just amplify codegen ffs

@isaac-rosterlab
Copy link

Why in the name of all that is holy, do I need to use amplify api gql-compile && amplify codegen instead of just amplify codegen ffs

To take it one step further, why not: "amplify api gql-compile && amplify codegen && amplify codegen models" instead of just "amplify codegen". Also, this workaround should probably be entered in the docs somewhere.

@pencilcheck
Copy link

pencilcheck commented Feb 28, 2022

After doing all those latest answer with new scripts, the model which are renamed in the cloud didn't get synced to the local JS files. All models created are synced but the existing models renamed are not replaced.

@cjsilva-umich
Copy link

Three and a half YEARS later and the behavior is still not like the docs...

At least the mentioned workaround does the trick sometimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amplify-codegen Issues on amplify-codegen
Projects
None yet
Development

No branches or pull requests