javascript - การสืบค้นหลายฟิลด์ที่มีค่าเดียวกัน [GraphQL][Amplify]
ฉันกำลังสร้าง API ด้วย AWS Amplify และ AppSync GraphQL ฉันกำลังทำงานเกี่ยวกับแอปที่คล้ายกับ Tinder
ฉันต้องการค้นหาค่าที่เหมือนกันในสองฟิลด์สำหรับการค้นหา ฉันได้ลองวิธีแก้ไขหลายวิธี แต่ไม่มีวิธีใดที่ดูเหมือนจะใช้ได้ผล
ฉันมีผู้ใช้ @Model ซึ่งเชื่อมต่อกับ Match หลายรายการผ่าน @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"])
}
และฉันมี Match @Model ซึ่งมีฟิลด์ senderId และฟิลด์ receiverId
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
}
และฉันก็ไม่พบวิธีใดที่จะทำให้ bySender @key ค้นหาทั้ง senderId และ receiverId ฉันต้องการที่จะสามารถมี Matches ทั้งหมดสำหรับ User ไม่ว่าเขาจะเป็นผู้รับหรือผู้ส่ง
แต่เมื่อฉันทำ Query ไปยัง ListUsers ฉันจะได้เพียง Matches ที่ User เป็นผู้รับเท่านั้น
ฉันก็ได้ลองสร้าง @connection หลายตัวแล้ว แต่ Graphql-transformer ไม่อนุญาต
ฉันก็พยายามสร้าง usersId: [ID!]! แบบนั้นด้วย
type Match @model {
...
usersId: [ID!]!
users: [User!]!
@connection(fields: ["usersId"])
...
}
แต่มันก็ไม่ได้รับอนุญาตโดย graphql-transformer เช่นกัน..
มีใครมีวิธีแก้ปัญหาในการดึงแมทช์ทั้งหมดของ User ไหม?
ขอบคุณมาก!