Fields marked with @hasInverse do not populate in @lambda parent object

Hey @kdilla301,

IIRC, only ‘scalars’ are sent to lambda handlers. So this limits what can be done, but I think I have a solution for you.

Note that there are two types of lambdas: query resolvers and mutation handlers. You’re sort of mixing the two here. Based on what you posted, I believe the best solution is for the high_score edge to be a query resolver, not a mutation lambda.

Here’s a query resolver that should do the trick…

lambda JS:

async function calculateHighScore({parent, graphql}) {
    const results = await graphql(`
    query {
        getUser(id: "${parent.id}") {
          id
          scores(order: {desc: score}, first: 1) {
            score
            record_date
          }
        }
    }`)
    return {
        user: {id: parent.id},
        score: results.data.getUser.scores[0].score,
        record_date: results.data.getUser.scores[0].record_date
    }
}

self.addGraphQLResolvers({
    "User.high_score": calculateHighScore
})