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

TypeError while generating modelgen in dart

Open silentlie opened this issue 1 year ago • 0 comments

Environment information

System:
  OS: Windows 10 10.0.19045
  CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
  Memory: 4.20 GB / 15.92 GB
Binaries:
  Node: 22.0.0 - C:\Program Files\nodejs\node.EXE       
  Yarn: undefined - undefined
  npm: 10.8.0 - C:\Program Files\nodejs\npm.CMD
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.0
  @aws-amplify/backend: 1.1.1
  @aws-amplify/backend-auth: 1.1.3
  @aws-amplify/backend-cli: 1.2.5
  @aws-amplify/backend-data: 1.1.2
  @aws-amplify/backend-deployer: 1.1.0
  @aws-amplify/backend-function: 1.3.3
  @aws-amplify/backend-output-schemas: 1.2.0
  @aws-amplify/backend-output-storage: 1.1.1
  @aws-amplify/backend-secret: 1.1.0
  @aws-amplify/backend-storage: 1.1.2
  @aws-amplify/cli-core: 1.1.2
  @aws-amplify/client-config: 1.2.1
  @aws-amplify/deployed-backend-client: 1.4.0
  @aws-amplify/form-generator: 1.0.1
  @aws-amplify/model-generator: 1.0.5
  @aws-amplify/platform-core: 1.0.6
  @aws-amplify/plugin-types: 1.2.1
  @aws-amplify/sandbox: 1.2.0
  @aws-amplify/schema-generator: 1.2.1
  aws-amplify: 6.5.2
  aws-cdk: 2.154.1
  aws-cdk-lib: 2.154.1
  typescript: 5.5.4
AWS environment variables:
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
  AWS_STS_REGIONAL_ENDPOINTS = regional
No CDK environment variable

Codegen packages

[email protected] G:\ADSATS\adsats_amplify_gen_2
└─┬ @aws-amplify/[email protected]
  └─┬ @aws-amplify/[email protected]
    └── @aws-amplify/[email protected]

Description

Describe the bug:

A model that has composite identifier will cause TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo') while generating graphql model client code

TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo')
[DEBUG] 2024-09-18T10:20:44.432Z: TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo')
    at AppSyncModelDartVisitor.getModelIdentifierFields (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:874:51)
    at AppSyncModelDartVisitor.generateGetters (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:268:47)
    at AppSyncModelDartVisitor.generateModelClass (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:168:14)
    at G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:116:43
    at Array.forEach (<anonymous>)
    at AppSyncModelDartVisitor.generateModelClasses (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:115:50)
    at AppSyncModelDartVisitor.generate (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:31:21)
    at Object.plugin (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\plugin.js:55:24)
    at G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\graphql-generator\node_modules\@graphql-codegen\core\cjs\execute-plugin.js:36:54
    at G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\graphql-generator\node_modules\@graphql-codegen\core\node_modules\@graphql-codegen\plugin-helpers\cjs\profiler.js:7:49

How can this bug be reproduced?

  1. Create two models and a many-to-many model in between
  2. Specify the identifiers by those two Ids
  3. Run npx ampx generate graphql-client-code --format modelgen --model-target dart --out lib/models --branch dev --debug

Please include any code snippets or screenshots that you think would be helpful!

NoticeStaff: a
  .model({
    read_at: a.datetime(),
    noticeId: a.id().required(),
    staffId: a.id().required(),
    notice: a.belongsTo("Notice", "noticeId"),
    staff: a.belongsTo("Staff", "staffId"),
  })
  .identifier(["noticeId", "staffId"]),

npx ampx generate graphql-client-code --format modelgen --model-target dart --out lib/models --branch dev --debug

silentlie avatar Sep 18 '24 10:09 silentlie