I'm creating an API with AWS Amplify and AppSync GraphQL. I Work on a Tinder like App.
I would like to search the same value in two fields for a Query. I've tried a lot of solutions, but none seems to work.
I have a User @Model which is connected to many Match via @connection
type User @model
@auth(rules: [{allow: public}])
{
id: ID!
email: String!
password: String
age: String!
name: String!
description: String
pickupLine: String
orientation: Orientation!
gender: Gender!
animal: Animal!
profilePicture: String!
pictures: [String]!
location: Location
numberOfSparksAvailable: Int!
matchs: [Match]
@connection(keyName: "byUser", fields: ["id"])
sparks: [Spark]
@connection(keyName: "byUser", fields: ["id"])
}
And I have a Match @Model which have a senderId field and a receiverId field
type Match @model
@auth(rules: [{allow: public}])
@key(name: "byUser", fields: ["receiverId", "senderId"], queryField: "matchByUser")
@key(name: "bySender", fields: ["senderId"], queryField: "sparkBySender")
@key(name: "byReceiver", fields: ["receiverId"], queryField: "sparkByReceiver")
{
id: ID!
status: MatchStatus!
matchType: MatchType
sender: User! @connection(fields: ["senderId"])
senderId: ID!
receiver: User! @connection(fields: ["receiverId"])
receiverId: ID!
answerFrom: Answer!
answerTo: Answer
chatRoomId: ID!
chatRoom: ChatRoom!
@connection(fields: ["chatRoomId"])
deletedAt: AWSDate
}
And and I don't find any way to make bySender @key look for both senderId and receiverId. I want to be able to have all the Matches for a User whether he's the receiver or the sender.
But when I make a Query to ListUsers I only get the Matches where the User is a receiver.
I've also tried to make multiple @connection but it is not allowed by Graphql-transformer.
I also tried to make an usersId: [ID!]! like that
type Match @model {
...
usersId: [ID!]!
users: [User!]!
@connection(fields: ["usersId"])
...
}
But It's also not allowed by graphql-transformer..
Has anyone a solution to get all the matches for a User?
Thanks a lot !