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

npx ampx generate graphql-client-code --model-target typescript --out graphql generates schema generates different schema. #2506

Closed
vjjcn opened this issue Feb 13, 2025 · 3 comments
Labels
pending-response Issue is pending response from author pending-triage Incoming issues that need categorization transferred Issue was transferred from another Amplify repository

Comments

@vjjcn
Copy link

vjjcn commented Feb 13, 2025

Environment information

System:
  OS: macOS 15.2
  CPU: (10) arm64 Apple M1 Pro
  Memory: 177.06 MB / 32.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.17.0 - /usr/local/bin/node
  Yarn: undefined - undefined
  npm: 10.8.2 - /usr/local/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.1
  @aws-amplify/backend: 1.5.0
  @aws-amplify/backend-auth: 1.2.0
  @aws-amplify/backend-cli: 1.2.9
  @aws-amplify/backend-data: 1.1.4
  @aws-amplify/backend-deployer: 1.1.5
  @aws-amplify/backend-function: 1.7.0
  @aws-amplify/backend-output-schemas: 1.3.0
  @aws-amplify/backend-output-storage: 1.1.2
  @aws-amplify/backend-secret: 1.1.4
  @aws-amplify/backend-storage: 1.2.1
  @aws-amplify/cli-core: 1.1.3
  @aws-amplify/client-config: 1.4.0
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.0
  @aws-amplify/sandbox: 1.2.3
  @aws-amplify/schema-generator: 1.2.4
  aws-amplify: 6.6.6
  aws-cdk: 2.163.1
  aws-cdk-lib: 2.163.1
  typescript: 5.6.3
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Data packages

[email protected] /Users/vadirajc/Downloads/generate-test-2
├─┬ @aws-amplify/[email protected]
│ └─┬ @aws-amplify/[email protected]
│   └── @aws-amplify/[email protected]
└─┬ @aws-amplify/[email protected]
  └─┬ @aws-amplify/[email protected]
    └── @aws-amplify/[email protected]

Description

Hello Community,

I have recently discovered that when I run
npx ampx generate graphql-client-code --model-target typescript --out graphql in the amplify app directory it generates the code for the schema from amplify/data/resource.ts from the last deployed sandbox stack in the local system.

This is the documentation for the code
[+] https://docs.amplify.aws/react/reference/cli-commands/#npx-ampx-generate-graphql-client-code


How i observed the issue

  1. Created amplify app from the quickstart template.
    [+] https://docs.amplify.aws/react/start/quickstart/
  2. Created a clone in the local machine
  3. Installed node modules using npm install
  4. Downloaded amplify_outputs.json in the application
  5. Ran npx ampx generate graphql-client-code --model-target typescript --out graphql

To my surprise the code was taking schema from entirely different amplify application. I have verified the current working directory by 'pwd' and it was the correct directory.

Later i could observe that it is taking the last deployed schema from the last deployed sandbox in the machine.


To further verify the observation and replication steps

  1. Created 2 amplify apps A and B from the quickstart template
    [+] https://docs.amplify.aws/react/start/quickstart/
  2. Installed node modules in both the apps using npm install.
  3. In the amplify app A run the sandbox box by
    'npx ampx sandbox'
  4. To change the schema in the app A, change the amplify/data/resource.ts by adding any additional fields.
  5. Go to app B, run the command
    npx ampx generate graphql-client-code --model-target typescript --out graphql
  6. This will generate the code based on the schema from the app A. Verified the current directory by 'pwd' , looks correct.

Later after deep dive, I could observe that the the app name in the package.json is same for both the application "amplify-vite-react-template".
CLI uses the package name in package.json to generate sandbox identifiers. If two projects accidentally share the same package name, it can cause some sandbox identifier conflicts.

Amplify recommends using the amplify quick start template, but if a user is creating a multiple apps in the system, it can cause this strange behavior as all the apps will have the same name if created from the quickstart template and the generate code will take the last deployed sandbox stack instead of the local file.

This should be clear in the documentation or amplify docs should recommend installing the app manually instead of using templates which can cause this type of behavior.

Thank you

@vjjcn vjjcn added the pending-triage Incoming issues that need categorization label Feb 13, 2025
@AnilMaktala
Copy link
Member

Hey @vjjcn, Thank you for reporting this and sharing the details. Transferring the issue to the CodeGen repo for better support.

@AnilMaktala AnilMaktala added the transferred Issue was transferred from another Amplify repository label Feb 13, 2025
@AnilMaktala AnilMaktala transferred this issue from aws-amplify/amplify-category-api Feb 13, 2025
@AnilMaktala AnilMaktala transferred this issue from aws-amplify/amplify-codegen Feb 13, 2025
@ykethan
Copy link
Member

ykethan commented Feb 13, 2025

Hey @vjjcn, thank you for reaching. As you have correctly pointed, the command uses the name property from the package.json as part of the default identifier. In your local sandbox command you can include the --identifier argument to deploy the stack with a different identifier. Additionally, at the start of sandbox the CLI should also provide an output with the identifier and the name of the stack being deployed to.

Image

this behavior does not effect branch deploys as the pipeline-deploy command uses Amplify AppID and branch name as part of the identifiers.

@ykethan ykethan added the pending-response Issue is pending response from author label Feb 13, 2025
@ykethan
Copy link
Member

ykethan commented Feb 24, 2025

Closing the issue due to inactivity. Do reach out to us if you require any further information.

@ykethan ykethan closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-response Issue is pending response from author pending-triage Incoming issues that need categorization transferred Issue was transferred from another Amplify repository
Projects
None yet
Development

No branches or pull requests

3 participants