aws-amplify / amplify-codegen

Amplify Codegen is a JavaScript toolkit library for frontend and mobile developers building Amplify applications.
Apache License 2.0
60 stars 63 forks source link

Can't generate models if schema used identifier function #909

Open robot-apocalypse opened 6 days ago

robot-apocalypse commented 6 days ago

Environment information

System:
  OS: macOS 15.1
  CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Memory: 40.66 MB / 32.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 22.6.0 - ~/.nvm/versions/node/v22.6.0/bin/node
  Yarn: undefined - undefined
  npm: 10.8.2 - ~/.nvm/versions/node/v22.6.0/bin/npm
  pnpm: 9.11.0 - ~/.nvm/versions/node/v22.6.0/bin/pnpm
NPM Packages:
  @aws-amplify/auth-construct: Not Found
  @aws-amplify/backend: Not Found
  @aws-amplify/backend-auth: Not Found
  @aws-amplify/backend-cli: 1.4.2
  @aws-amplify/backend-data: Not Found
  @aws-amplify/backend-deployer: 1.1.9
  @aws-amplify/backend-function: Not Found
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: Not Found
  @aws-amplify/backend-secret: 1.1.5
  @aws-amplify/backend-storage: Not Found
  @aws-amplify/cli-core: 1.2.0
  @aws-amplify/client-config: 1.5.2
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.9
  @aws-amplify/platform-core: 1.2.0
  @aws-amplify/plugin-types: 1.4.0
  @aws-amplify/sandbox: 1.2.5
  @aws-amplify/schema-generator: 1.2.5
  aws-amplify: 6.8.2
  aws-cdk: 2.164.1
  aws-cdk-lib: 2.164.1
  typescript: 5.6.3
AWS environment variables:
  AWS_PAGER =
  AWS_PROFILE = crowder
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the bug

It seems like if I specify an identifier on my schema models, then I'm not able to generate graphql-client-code. If I do have an identifier, whether composite or single value, i get the following error when I run the generate command: TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo')

Reproduction steps

I have a schema model like so:

Crowd: a
    .model({
      createdAt: a.timestamp().required(),
      lastModifiedAt: a.timestamp(),
      userId: a.id().required(),
      user: a.belongsTo('User', 'userId'),
      shopId: a.id().required(),
      shop: a.belongsTo('Shop', 'shopId'),
      offer: a.float(),
      productURL: a.string(),
      productId: a.string().required(),
    })
    .identifier(['userId', 'shopId', 'productId'])
    .authorization((allow) => [allow.publicApiKey()])

The goal is to have a composite identifier made up of userId, shopId and productId, but I have also tried with just e.g shopId and gotten the same result.

The command I run is: npx ampx generate graphql-client-code --format modelgen --model-target dart --out lib/src/db --stack <stack-name>

ykethan commented 4 days ago

Hey,👋 thanks for raising this! I'm going to transfer this over to our codegen repository for better assistance 🙂