aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 819 forks source link

An error occurred during the push operation: Could not find a schema at /home/user/projectName/amplify/backend/api/appSyncApiName/schema.graphql #9721

Closed charlesdarkwind closed 2 years ago

charlesdarkwind commented 2 years ago

Before opening, please confirm:

How did you install the Amplify CLI?

No response

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

No response

Amplify CLI Version

7.6.14

What operating system are you using?

Mac, Windows and Ubuntu

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

No

Amplify Categories

api, hosting

Amplify Commands

publish, push

Describe the bug

The project has no backend or schema definition of its own, it uses manual hosting. The types are generated using amplify codegen of types from another appsync API using amplify codegen (script used as codegen unfortunetly does not have headless support ):

#!/usr/bin/expect -f

set timeout -1
spawn amplify add codegen --apiId "$env(API_ID)"
expect "target"
send "\033\[B"
send "\r"
expect "ts)"
send "\r"
expect "(Y/n)"
send "n\r"
expect "(src/API.ts)"
send "\r"
expect "(Y/n)"
send "\r"
expect eof

Since we upgraded to this amplify version, the amplify publish commands (and amplify push) give the following error:

(base) user@DESKTOP-EI7Q1CL:~/projectName$ amplify publish --yes
✖ There was an error pulling the backend environment dev.
🛑 An error occurred during the push operation: Could not find a schema at /home/user/projectName/amplify/backend/api/appSyncApiName/schema.graphql`

If we generate an empty file manually then the command succeeds.

mkdir -p amplify/backend/api/appSyncApiName && touch amplify/backend/api/appSyncApiName/schema.graphql

(base) user@DESKTOP-EI7Q1CL:~/projectName$ amplify publish --yes
✔ Successfully pulled backend environment dev from the cloud.

    Current Environment: dev

┌──────────┬────────────────┬───────────┬───────────────────┐
│ Category │ Resource name  │ Operation │ Provider plugin   │
├──────────┼────────────────┼───────────┼───────────────────┤
│ Api      │  projectName   │ Create    │                   │
├──────────┼────────────────┼───────────┼───────────────────┤
│ Hosting  │ amplifyhosting │ No Change │ awscloudformation │
└──────────┴────────────────┴───────────┴───────────────────┘
✔ All resources are updated in the cloud

GraphQL transformer version: 1

Publish started for amplifyhosting

> client@0.1.0 build
> craco build

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  1.62 MB    build/static/js/2.ca3ea0ff.chunk.js
  300.26 KB  build/static/js/main.b8facb9b.chunk.js
  4.94 KB    build/static/css/2.b53d0174.chunk.css
  772 B      build/static/js/runtime-main.776c1e0d.js
  323 B      build/static/css/main.b1bc96b3.chunk.css

The bundle size is significantly larger than recommended.
Consider reducing it with code splitting: https://goo.gl/9VhYWB
You can also analyze the project dependencies: https://goo.gl/LeUzfb

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

  npm install -g serve
  serve -s build

Find out more about deployment here:

  https://cra.link/deployment

✔ Zipping artifacts completed.
✔ Deployment complete!
https://dev.xxx.amplifyapp.com

Trying with 7.6.7 was also working.

Expected behavior

The amplify publish --yes commands runs normally with no errors

Reproduction steps

use amplify publish on a minimal project with types generated from another API.

GraphQL schema(s)

```graphql # Put schemas below this line ```

Log output

``` # Put your logs below this line ```

Additional information

Environment information

Bug appears on Windows and Mac with same Amplify version

``` System: OS: Linux 4.19 Ubuntu 20.04.3 LTS (Focal Fossa) CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor Memory: 21.17 GB / 25.00 GB Container: Yes Shell: 5.0.17 - /bin/bash Binaries: Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node Yarn: 1.22.5 - /mnt/c/Program Files (x86)/Yarn/bin/yarn npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm npmPackages: @apideck/file-picker: https://github.com/Conova-ai/file-picker/tarball/master => 0.6.0 @auth0/auth0-spa-js: ^1.14.0 => 1.19.3 @aws-amplify/analytics: ^4.0.17 => 4.0.22 @aws-amplify/api: ^3.2.29 => 3.3.3 @aws-amplify/auth: ^3.4.29 => 3.4.34 (3.4.21) @aws-amplify/core: ^3.8.21 => 3.8.24 (3.8.13) @aws-amplify/interactions: ^3.3.29 => 3.3.34 (3.3.21) @aws-amplify/storage: ^3.3.29 => 3.4.4 (3.3.21) @aws-amplify/ui-react: ^0.2.38 => 0.2.38 @aws-amplify/xr: ^2.2.29 => 2.2.34 (2.2.21) @aws-sdk/client-s3: ^3.49.0 => 3.49.0 (3.6.1, 1.0.0-rc.4) @conova/coach-ui-library: ^1.45.1 => 1.45.1 @craco/craco: 6.2.0 => 6.2.0 @graphql-tools/graphql-file-loader: ^7.1.0 => 7.3.3 @graphql-tools/load: ^7.3.2 => 7.5.1 @material-ui/core: ^4.11.0 => 4.12.3 @material-ui/icons: ^4.11.2 => 4.11.2 @material-ui/lab: ^4.0.0-alpha.56 => 4.0.0-alpha.60 @microsoft/file-browser: ^1.0.0-preview.0 => 1.0.0-preview.0 @microsoft/microsoft-graph-client: ^3.0.0 => 3.0.1 @stripe/stripe-js: ^1.15.0 => 1.22.0 @testing-library/dom: ^7.30.2 => 7.31.2 (6.16.0) @testing-library/jest-dom: ^4.2.4 => 4.2.4 @testing-library/react: ^9.3.2 => 9.5.0 @testing-library/user-event: ^7.1.2 => 7.2.1 @types/chrome: 0.0.133 => 0.0.133 @types/dompurify: ^2.2.2 => 2.3.2 @types/dotenv: ^8.2.0 => 8.2.0 @types/google.picker: 0.0.39 => 0.0.39 @types/jest: ^24.9.1 => 24.9.1 @types/lodash: ^4.14.165 => 4.14.178 @types/material-ui: ^0.21.8 => 0.21.12 @types/node: ^12.20.7 => 12.20.41 @types/react: ^16.14.5 => 16.14.21 @types/react-dom: ^16.9.12 => 16.9.14 @types/react-helmet: ^6.1.0 => 6.1.5 @types/react-phone-number-input: ^3.0.6 => 3.0.13 @types/react-router-dom: ^5.1.5 => 5.3.2 @types/segment-analytics: 0.0.33 => 0.0.33 aws-amplify: ^3.3.26 => 3.4.3 aws-amplify-react: ^4.2.30 => 4.2.35 aws-appsync: ^4.0.3 => 4.1.4 axios: ^0.21.1 => 0.21.4 (0.24.0, 0.21.1) chai: ^4.3.4 => 4.3.4 cross-var: ^1.1.0 => 1.1.0 dompurify: ^2.2.9 => 2.3.4 dotenv: ^8.2.0 => 8.6.0 (8.2.0) dotenv-cli: ^4.0.0 => 4.1.1 email-validator: ^2.0.4 => 2.0.4 example: 1.0.0 file-type: ^16.5.3 => 16.5.3 form-data: ^4.0.0 => 4.0.0 (3.0.1) gapi-script: ^1.2.0 => 1.2.0 graphql: ^15.6.0 => 15.8.0 (14.0.0) graphql-tag: ^2.11.0 => 2.12.6 graphql-tools: ^8.2.0 => 8.2.0 graphql-tools/es5: 8.2.0 husky: ^4.3.8 => 4.3.8 i18next: ^19.9.2 => 19.9.2 i18next-browser-languagedetector: ^6.1.0 => 6.1.2 i18next-http-backend: ^1.2.1 => 1.3.1 jwt-decode: ^3.1.2 => 3.1.2 lint-staged: ^10.5.4 => 10.5.4 lodash: ^4.17.21 => 4.17.21 mocha: ^9.1.2 => 9.1.3 moment: ^2.29.1 => 2.29.1 prettier: ^2.2.1 => 2.5.1 query-string: ^6.14.1 => 6.14.1 (4.3.4) react: ^16.14.0 => 16.14.0 react-dom: ^16.14.0 => 16.14.0 react-dropzone: ^11.4.2 => 11.4.2 react-google-drive-picker: ^1.1.4 => 1.1.4 react-helmet: ^6.1.0 => 6.1.0 react-i18next: ^11.8.12 => 11.15.3 react-infinite-scroll-component: ^5.1.0 => 5.1.0 react-intersection-observer: ^8.32.0 => 8.33.1 react-moment: ^1.1.1 => 1.1.1 react-onedrive-filepicker: ^0.1.3 => 0.1.3 react-phone-number-input: ^3.1.22 => 3.1.45 react-phone-number-input-core: 1.0.0 react-phone-number-input-flags: 1.0.0 react-phone-number-input-input-core: 1.0.0 react-phone-number-input-input-max: 1.0.0 react-phone-number-input-input-min: 1.0.0 react-phone-number-input-input-mobile: 1.0.0 react-phone-number-input-max: 1.0.0 react-phone-number-input-min: 1.0.0 react-phone-number-input-mobile: 1.0.0 react-phone-number-input/react-hook-form: 1.0.0 react-phone-number-input/react-hook-form-core: 1.0.0 react-phone-number-input/react-hook-form-input: 1.0.0 react-phone-number-input/react-hook-form-input-core: 1.0.0 react-phone-number-input/react-native-input: 1.0.0 react-router-dom: ^5.2.0 => 5.3.0 react-schemaorg: ^1.2.0 => 1.3.3 react-scripts: 4.0.3 => 4.0.3 sass: ^1.44.0 => 1.46.0 schema-dts: ^0.7.1 => 0.7.4 typescript: ^3.8.0 => 3.9.10 npmGlobalPackages: @aws-amplify/cli: 7.6.14 corepack: 0.10.0 npm: 8.1.2 ```
ammarkarachi commented 2 years ago

@charlesdarkwind Thanks for the issue, does a file called .graphqlconfig.yml get generated and can you share its contents?

I am unable to reproduce with 7.6.15

charlesdarkwind commented 2 years ago

@ammarkarachi sure, here is the file

projects:
  projectName-env:
    schemaPath: src/graphql/schema.json
    includes:
      - src/graphql/**/*.ts
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: typescript
        generatedFileName: src/API.ts
        docsFilePath: src/graphql
        region: ca-central-1
        apiId: AppSyncApiID
ammarkarachi commented 2 years ago

@charlesdarkwind Thanks for the prompt reply. The issue stems from the absence of this flag. If you add this to your amplify/cli.json

{
  "features": {
    "graphqltransformer": {
      "addmissingownerfields": true,
      "improvepluralization": false,
      "validatetypenamereservedwords": true,
      "useexperimentalpipelinedtransformer": true,
      "enableiterativegsiupdates": true,
      "secondarykeyasgsi": true,
      "skipoverridemutationinputtypes": true,
      "transformerversion": 2,
      "suppressschemamigrationprompt": true,
--->"securityenhancementnotification": false
    },
...
}

Should unblock you in the mean time we work on fixing this bug.

charlesdarkwind commented 2 years ago

@ammarkarachi Thanks, I confirm that this flag fixes the problem.

coe720 commented 2 years ago

I tried to add this flag but it didn't fix the issue for me

WiL-dev commented 2 years ago

@charlesdarkwind Thanks for the prompt reply. The issue stems from the absence of this flag. If you add this to your amplify/cli.json

{
  "features": {
    "graphqltransformer": {
      "addmissingownerfields": true,
      "improvepluralization": false,
      "validatetypenamereservedwords": true,
      "useexperimentalpipelinedtransformer": true,
      "enableiterativegsiupdates": true,
      "secondarykeyasgsi": true,
      "skipoverridemutationinputtypes": true,
      "transformerversion": 2,
      "suppressschemamigrationprompt": true,
--->"securityenhancementnotification": false
    },
...
}

Should unblock you in the mean time we work on fixing this bug.

For me, the following flag was the one that workaround the problem

"showfieldauthnotification": false

"features": {
    "graphqltransformer": {
    "addmissingownerfields": true,
    "improvepluralization": false,
    "validatetypenamereservedwords": true,
    "useexperimentalpipelinedtransformer": true,
    "enableiterativegsiupdates": true,
    "secondarykeyasgsi": true,
    "skipoverridemutationinputtypes": true,
    "transformerversion": 2,
    "suppressschemamigrationprompt": true,
    "securityenhancementnotification": false,
--->"showfieldauthnotification": false
},
coe720 commented 2 years ago

How long does the fix take to be merged into the amplify-cli after it's complete? I updated to 7.6.22 but still seeing the error.

github-actions[bot] commented 2 years ago

👋 Hi, this issue was referenced in the v7.6.23 release!

Check out the release notes here https://github.com/aws-amplify/amplify-cli/releases/tag/v7.6.23.