Value not found at path

I have a document in the Player collection:

{
"ref": Ref(Collection("Player"), "282953608634302981"),
"ts": 1606104439300000,
"data": {
"rankingid": "282953512300577285",
"uid": "282953404609724933",
"rank": 1,
"challengerid": ""
}
}

a succesfully updated schema update:

gotPlayersByRankingId (rankingid: String!): [Player] @resolver(name: "got_players_byrankingid")

an index :

{
  name: "playersByRankingId",
  unique: false,
  serialized: true,
  source: "Player",
  terms: [
    {
      field: ["data", "rankingid"]
    }
  ]
}

a function:

{
  name: "got_players_byrankingid",
  role: null,
  body: Query(
    Lambda(
      ["rankingid"],
      Let(
        { player: Match(Index("playersByRankingId"), Var("rankingid")) },
        { player: Select("data", Var("player")) }
      )
    )
  )
}

in PG:

query GotPlayersByRankingId {
gotPlayersByRankingId(rankingid: "282953512300577285") {
_id
rankingid
uid
rank
challengerid
}
}

Gives me:

{
"errors": [
{
"message": "Value not found at path [data].",
"extensions": {
"code": "value not found"
}
}
]
}

I tried adding P (capital P) and player {…} in PG as well:
Gives me:

"message": "Cannot query field '(P)player' on type 'Player'.

What do I need to change to return a list of players matching rankingid?
thanks …

Match doesn’t return a Document, it returns a SetRef. On top of that, your graphql schema says that you are returning an array of Players, so your UDF should return an array of Player Documents

Once you use Paginate on the SetRef, you’ll get a Page of players of whatever size you choose. So after converting the player refs to documents with Map, you will have to pull the actual data array of Player Documents out of the Page and return it directly (The Map function automagically works on the Page's data array, and then returns the results as a Page instead of a raw array if you pass it a Page).

{
  name: "got_players_byrankingid",
  role: null,
  body: Query(
    Lambda(
      ["rankingid"],
      Let(
        { 
            playerSetRef: Match(Index("playersByRankingId"), Var("rankingid")),
            playerDocumentsPage: Map(
                  Paginate(Var("playerSetRef"), {size: 100}), 
                  Lambda("playerRef", Get(Var("playerRef")))
             )
        },
        Select(['data'], Var("playerDocumentsPage"))
    )
  )
}
1 Like

@wallslide … thanks, that worked. Thanks also for taking the time to explain why :+1: :smiley:

1 Like