amplify-js
amplify-js copied to clipboard
@hasMany on table with @primaryKey w/ sort field not working
Before opening, please confirm:
- [X] I have searched for duplicate or closed issues and discussions.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
Not applicable
Amplify APIs
GraphQL API
Amplify Categories
api
Environment information
# Put output below this line
System:
OS: Linux 5.10 Ubuntu 20.04 LTS (Focal Fossa)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Memory: 7.61 GB / 9.63 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 18.7.0 - /usr/bin/node
npm: 8.15.0 - /usr/bin/npm
npmPackages:
@aws-amplify/ui-react: ^2.20.0 => 2.20.0
@aws-amplify/ui-react-internal: undefined ()
@aws-amplify/ui-react-legacy: undefined ()
@testing-library/jest-dom: ^5.16.4 => 5.16.4
@testing-library/react: ^13.3.0 => 13.3.0
@testing-library/user-event: ^13.5.0 => 13.5.0
aws-amplify: ^4.3.28 => 4.3.28
react: ^18.2.0 => 18.2.0 (18.0.0)
react-dom: ^18.2.0 => 18.2.0
react-helmet: ^6.1.0 => 6.1.0
react-helmet-async: ^1.3.0 => 1.3.0
react-scripts: 5.0.1 => 5.0.1
web-vitals: ^2.1.4 => 2.1.4
npmGlobalPackages:
@aws-amplify/cli: 9.1.0
corepack: 0.12.1
npm: 8.15.0
Describe the bug
The GraphQL schema directive @hasMany doesn't appear to work in combination with a table that has a hash key and sort key set via @primaryKey. Using the generated "getAlphas" query returns no "Bravos".
Expected behavior
await API.graphql(graphqlOperation(getAlpha, {
AlphaId: '123'
}))
should return "Bravos" with matching AlphaId, but does not.
Reproduction steps
- deploy a GraphQL API with a schema of the form:
type Alpha @model {
AlphaId: ID! @primaryKey
label: String
Bravos: [Bravo] @hasMany
}
type Bravo @model {
AlphaId: ID! @primaryKey(sortKeyFields: ["BravoId"])
BravoId: ID!
label: String
}
- Populate tables with one Alpha and multiple Bravos with a common AlphaID
- Attempt to query for Bravos on Alpha:
await API.graphql(graphqlOperation(getAlpha, {
AlphaId: '123'
}))
- Observe that while the Alpha entry is returned, the Bravos are not.
Code Snippet
No response
Log output
No response
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response