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

amplify codegen generates empty API.ts and non-typescript operation files in github actions workflow

Open gilbertchua322 opened this issue 2 years ago • 9 comments

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. image image

Here is my .graphqlconfig.yml: image 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:

  1. yarn global add @aws-amplify/cli
  2. amplify codegen --nodownload

GraphQL schema(s)

No response

Log output

No response

Additional information

No response

gilbertchua322 avatar May 27 '22 06:05 gilbertchua322

Transferring to amplify-codegen repo

InnovateWithEric avatar May 27 '22 17:05 InnovateWithEric

Any update on this. I'm getting the same issue.

lewisdonovan avatar Nov 12 '22 18:11 lewisdonovan

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?

lewisdonovan avatar Nov 12 '22 19:11 lewisdonovan

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.

mctang719 avatar Nov 15 '22 04:11 mctang719

May be resolved by https://github.com/aws-amplify/amplify-codegen/pull/690. Requires testing.

dpilch avatar Sep 14 '23 16:09 dpilch

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!

DomGarza avatar Nov 05 '23 19:11 DomGarza

Can anyone confirm if this is still an issue?

dpilch avatar Nov 16 '23 15:11 dpilch

I'm facing this right now.

Frontrider avatar Apr 06 '24 18:04 Frontrider

Delete the AWS folder and re initialize it it'll come back

DomGarza avatar Apr 20 '24 23:04 DomGarza