amplify-category-api
amplify-category-api copied to clipboard
Object type extension 'Query' cannot redeclare field listByOwner
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
Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂
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.
@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")]),
});
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",
...
}
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.