Amplify-cli: Is the codegen command multi-env aware?

Created on 10 Apr 2019  路  8Comments  路  Source: aws-amplify/amplify-cli

* Which Category is your question related to? *
codegen

* What AWS Services are you utilizing? *
amplify cli, appsync, amplify codegen

* Provide additional details e.g. code snippets *
Is the codegen command multi-env aware? .graphqlconfig.yml does not change when I change envs.

bug code-gen

Most helpful comment

Hi @yuth - my scenario is I'm working in a dev environment, adding a new @model to the GraphQL AppSync API and so want codegen to produce code for this new model. Running amplify codegen alone in that environment does not produce the code for the updated API because .graphqlconfig.yml has graphQLApiId hardcoded to my prod GraphQL API id (from previous setup). I have to modify the .graphqlconfig.yml myself or run amplify configure codegen I believe to switch to the dev api. And then if I do these changes myself and switch to the prod environment, I have to run configure codegen again.

I am not sure what the endpoints parameter in .graphqlconfig.yml does. I used to have a "prod" endpoint in my old setup but when I ran amplify configure codegen and had it make a new yml file it removed the endpoints field.

My expectation was running amplify env checkout dev would change the .graphqlconfig.yml to the new dev GraphQL API and possibly run codegen for it.

And if I run amplify codegen add I get error saying only one GraphQL API is supported per project.

All 8 comments

@hisham its not multienv aware.

What exactly are you expecting by meaning multienv aware? Is it adding additional endpoints for each stage it encounters?

Hi @yuth - my scenario is I'm working in a dev environment, adding a new @model to the GraphQL AppSync API and so want codegen to produce code for this new model. Running amplify codegen alone in that environment does not produce the code for the updated API because .graphqlconfig.yml has graphQLApiId hardcoded to my prod GraphQL API id (from previous setup). I have to modify the .graphqlconfig.yml myself or run amplify configure codegen I believe to switch to the dev api. And then if I do these changes myself and switch to the prod environment, I have to run configure codegen again.

I am not sure what the endpoints parameter in .graphqlconfig.yml does. I used to have a "prod" endpoint in my old setup but when I ran amplify configure codegen and had it make a new yml file it removed the endpoints field.

My expectation was running amplify env checkout dev would change the .graphqlconfig.yml to the new dev GraphQL API and possibly run codegen for it.

And if I run amplify codegen add I get error saying only one GraphQL API is supported per project.

@hisham Yes, we should make this happen. I'll add it to my backlog.

Hi @yuth, I'd like to ask if this has been already implemented?
Running
$ amplify checkout env clientdev

doesn't update graphQLApiId in .graphqlconfig.yml.
Running
$ amplify --version
Returns 1.6.11

@dreadnautxbuddha yes it is. You can safely delete the hardcoded graphQLApiID in .graphqlconfig.yml. They now store the api id somewhere else.

thanks for the response @hisham. Just another question, for my project, I add AppSync APIs via
amplify add codegen --apiId <api id>. Will multienv work for this as well?

$ amplify env add test1
$ amplify codegen add --apiId xxxxxx
$ amplify codegen
$ amplify env add test2
$ amplify codegen add --apiId xxxxxx

I then get an error there that says only one api is allowed for project? Forgot the error, i'm not on my pc right now.

@dreadnautxbuddha yes it is. You can safely delete the hardcoded graphQLApiID in .graphqlconfig.yml. They now store the api id somewhere else.

We now retrieve the API ID from amplify-meta.json

thanks for the response @hisham. Just another question, for my project, I add AppSync APIs via
amplify add codegen --apiId <api id>. Will multienv work for this as well?

The CLI does not support using different API per environment when the API is externally added. The same API is shared across all the environment.

Ok. Thanks @yuth

Was this page helpful?
0 / 5 - 0 ratings