amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Object type extension 'Query' cannot redeclare field listByOwner

Open kekami opened this issue 10 months ago • 3 comments

Environment information

System:
  OS: macOS 14.4.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 291.50 MB / 32.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 18.20.0 - ~/.nvm/versions/node/v18.20.0/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.0/bin/yarn
  npm: 10.5.0 - ~/.nvm/versions/node/v18.20.0/bin/npm
  pnpm: 8.15.6 - /opt/homebrew/bin/pnpm
NPM Packages:
  @aws-amplify/backend: 0.13.0-beta.15
  @aws-amplify/backend-cli: 0.12.0-beta.17
  aws-amplify: 6.0.27
  aws-cdk: 2.136.0
  aws-cdk-lib: 2.136.0
  typescript: 5.4.4
AWS environment variables:
  AWS_SDK_LOAD_CONFIG = 1
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
No CDK environment variables

Description

The following scheme causes a deployment error due to both models tries to define a listByOwner query in Appsync.

const schema = a.schema({
  Todo: a
    .model({
      content: a.string(),
      owner: a.string().required(),
    })
    .authorization([a.allow.public()])
    .secondaryIndexes((index) => [index("owner")]),
  Article: a
    .model({
      content: a.string(),
      owner: a.string().required(),
    })
    .authorization([a.allow.public()])
    .secondaryIndexes((index) => [index("owner")]),
});

Error:

Failed to instantiate data construct
Caused By: Object type extension 'Query' cannot redeclare field listByOwner

kekami avatar Apr 06 '24 17:04 kekami

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

ykethan avatar Apr 08 '24 13:04 ykethan

Hey @kekami, Thank you for raising this. We can reproduce the issue by following the description. Hence, marking this as a bug for the team to evaluate further.

image

AnilMaktala avatar Apr 11 '24 00:04 AnilMaktala

@kekami , As an alternative solution, you can utilize the queryField to designate a custom name for the query, as demonstrated below. Please inform us if this assists in moving forward.

const schema = a.schema({
  Todo: a
    .model({
      content: a.string(),
      owner: a.string().required(),
    })
    .authorization([a.allow.public()])
    .secondaryIndexes((index) => [index("owner")]),
  Article: a
    .model({
      content: a.string(),
      owner: a.string().required(),
    })
    .authorization([a.allow.public()])
    .secondaryIndexes((index) => [index("owner").queryField("listByArticleOwner")]),
});

AnilMaktala avatar Apr 11 '24 00:04 AnilMaktala

Hey @kekami, This is fixed in the latest version of amplify-backend and amplify JS.

Please upgrade the following packages:

"dependencies": {
  "aws-amplify": "^6.2.0",
   ...
},
"devDependencies": {
  "@aws-amplify/backend": "^1.0.0",
  "@aws-amplify/backend-cli": "^1.0.0",
  ...
}

AnilMaktala avatar May 20 '24 15:05 AnilMaktala

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar May 20 '24 15:05 github-actions[bot]