On login I’m attempting to retrieve a list of Rankings to which the user belongs by adding a ‘userJoinedRankings’ to the loginResult @embedded type in my schema:
type User
{
active : Boolean!
username : String!
description : String
email : String
mobile : String
}
type Player
{ rankingid : String!
uid : String!
rank : Int!
challengerid : String
}
type Ranking
{
active : Boolean!
rankingname : String!
rankingdesc : String
rankingownerid : String!
}
type Mutation {
createAndOrLoginUser(active: Boolean!, username: String!, password: String!, description: String, email: String, mobile: String): String! @resolver(name: "create_andor_login_user")
createNewPlayer(rankingid: String!, uid: String!, rank: Int!, challengerid: String): Player! @resolver(name: "create_new_player")
createNewRanking(active: Boolean!, rankingname : String!, rankingdesc : String, rankingownerid : String!): Ranking! @resolver(name: "create_new_ranking")
createNewUser(active: Boolean!, username : String!, password : String!, description: String, email: String, mobile: String): loginResult! @resolver(name: "create_new_user")
}
type Query {
allUserNames: [String!]! @resolver(name: "all_user_names")
allPlayerUIDs: [String!]! @resolver(name: "all_player_uids")
allPlayerRanks: [Int!]! @resolver(name: "all_player_ranks")
allPlayerChallengerUIDs: [String!]! @resolver(name: "all_player_challenger_uids")
allPlayers: [Player] @resolver(name: "all_players")
allRankings: [Ranking] @resolver(name: "all_rankings")
allUsers: [User] @resolver(name: "all_users")
loginUser(username: String!, password: String!): loginResult! @resolver(name: "login_user")
gotPlayersByRankingId (rankingid: String!): [Player] @resolver(name: "got_players_byrankingid")
gotRankingIdsByPlayer (uid: String!): [String] @resolver(name: "got_rankings_byplayerid")
}
type loginResult @embedded
{
token : String
logginUser : User
userJoinedRankings : [String]
}
My intention is to use the document id of the User, once logged in, to query the rankingIdsByPlayer index (uid field) and return the relevant rankings as a list together with the User and a token.
The index:
{
name: "rankingIdsByPlayer",
unique: false,
serialized: true,
source: "Player",
terms: [
{
field: ["data", "uid"]
}
],
values: [
{
field: ["data", "rankingid"]
}
]
}
I will need to update the function. The closest I can get so far is:
Query(
Lambda(
["username", "password"],
Let(
{
match: Match(Index("unique_User_username"), Var("username")),
user: If(Exists(Var("match")), Get(Var("match")), "false"),
login: Login(Select("ref", Var("user")), { password: Var("password") }),
matchRankings: Match(Index("rankingIdsByPlayer"), Var("uid")),
userjoinrankings: Get(Var("matchRankings"))
},
{
token: Select("secret", Var("login")),
logginUser: Select("ref", Var("user")),
userjoinrankings: Select("ref", Var("userjoinrankings"))
}
)
)
)
This (correctly) gives me:
Variable 'uid' is not defined in the UI.
Is there a way for me to pass the just logged in user’s document id to matchRankings Match?
thanks …