amplify-codegen
amplify-codegen copied to clipboard
amplify codegen generates empty API.ts and non-typescript operation files in github actions workflow
Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have searched for duplicate or closed issues.
- [X] I have read the guide for submitting bug reports.
- [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.
How did you install the Amplify CLI?
yarn global add @aws-amplify/cli
If applicable, what version of Node.js are you using?
14.17.4
Amplify CLI Version
8.3.0
What operating system are you using?
Windows
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made
Amplify Categories
Not applicable
Amplify Commands
codegen
Describe the bug
Running amplify codegen on my local machine works fine, API.ts
is generated non-empty and mutations.ts
, queries.ts
, subscriptions.ts
are generated as well.
However, when running on Github Actions workflow, the API.ts
generated is empty and the files generated are in graphql format.
Here is my .graphqlconfig.yml:
This configuration is used on my local machine and its generating the correct files and
API.ts
isn't empty. But on Github Actions the result is different.
Expected behavior
Expect API.ts
to be non-empty with all types declared, and query/mutation/subscription files to be in .ts
format.
Reproduction steps
On Github actions workflow:
- yarn global add @aws-amplify/cli
- amplify codegen --nodownload
GraphQL schema(s)
No response
Log output
No response
Additional information
No response
Transferring to amplify-codegen repo
Any update on this. I'm getting the same issue.
Reading this issue thread https://github.com/aws-amplify/amplify-cli/issues/6269 I found that if I change the generatedFilename
in graphqlconfig.yaml
that's when I get a blank API.ts
file. If I leave the path as-is, it generates normally. Why does this option exist if it doesn't work?
I had the same issue initially with the path
includes:
- /graphql/**/*.ts
excludes:
- ./amplify/**
extensions:
amplify:
codeGenTarget: typescript
generatedFileName: /graphql/API.ts
The API.ts is generated in the folder I wanted to but with an empty API.ts
I removed the / in front of the graphql path.
- /graphql/
to - graphql/
It fixed the issue.
May be resolved by https://github.com/aws-amplify/amplify-codegen/pull/690. Requires testing.
If you're a newb like me and deleted your API.ts file you probably know you can restore it from recycle but here's the problem with that
- it will not be in sync with your current cloud data models
- Don't fall for the type safety correction in API.ts, because it will fix the type errors but it will not be correct types with your current data model
- If you deleted your API.ts file like I did, its not enough to restore an older version from recycle because it will not be in sync
Here's another thing to know, every time you make changes to your data model you have to re-run amplify codegen in order to have the updated types.
Here is what I had to do in order to get my API.ts back and in sync
Delete the following
- Amplify Folder
- GraphQL folder
- API.ts (if it is out of sync)
- amplifyconfiguration.json
- -aws-exports.js
- graphqlconfig.yml
You have to delete ALL of the above file in order to not have any conflicting files
Next Run
- Amplify Init
- amplify pull --whatever your env is from the cloud
- amplify add codegen
This way when you run amplify add codegen you can just go through the default settings without having to change paths names and ensure you have an in sync project
I wish it would automatically update the API.ts but this isn't the case, you have to run amplify codegen every time you update your data models to ensure they are in sync.
Hope this helps a newb like me out there!
Can anyone confirm if this is still an issue?
I'm facing this right now.
Delete the AWS folder and re initialize it it'll come back