List input to @connection fields parameter
See original GitHub issueWhich Category is your question related to? API, GraphQL, schema defnitions, documentation
Amplify CLI Version 4.24.0
What AWS Services are you utilizing? API
Provide additional details e.g. code snippets Hi guys, I have a type of relation in my data that I have been trying to solve for quite a while now. I have gone over the documentation but could find any information on how to achieve the desired result.
Lets say that I have two @models, one for Characters and one for Items. Characters can own items, which means there is a one way connection. If we are restricted to just a single item per character, I could define the schema like below:
type Character @model
{
id: ID!
itemId: String
item: Item @connection(fields: ["itemId"])
}
type Item @model
{
id: ID!
}
In this, multiple characters could own the same item, but there wouldn’t have to be any duplicate entries in the item database (because the characters point to the same object).
But now to my question, how do I achieve this kind of relation when a character can own many items? My hope was that I could do something like this:
type Character @model
{
id: ID!
itemIds: [String]
items: [Item] @connection(fields: ["itemIds"])
}
type Item @model
{
id: ID!
}
and that the resolver would loop over itemIds in order to fetch all of the items specified. However, as you can probably guess it does not work in this way and does not accept list inputs. So what is the recommended approach for these kinds of relations?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
There are two approaches.
This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels for those types of questions.