What I am doing:
I defined a custom mutation in the schema.graphql
:
type Mutation {
addPartner: User! @resolver(name: "addPartner")
}
This custom mutation should update the user document and then return back the updated value including.
Here’s what the User collection looks like:
type User @collection(name: "users") {
email: String! @unique
partner: User @relation
}
For simplicity, it doesn’t matter what the function does, it might be doing some validations or whatever, it’s completely irrelevant, in this scenario it’s pairing the user A
with another user – B – that is the A’s partner.
Here’s the function:
Update(Function("addPartner"), {
role: "admin",
body: Query(
Lambda(
["data"],
Update(
CurrentIdentity(),
{
data: {
partner: Ref(Collection("users"), "1231231312")
}
}
)
)
)
})
In this case, it’s hard coded, again, it’s doesn’t matter as long as the lambda returns Update
call it can be replicated,
So you’d assume you can do this:
mutation {
addPartner {
_id
email
partner {
_id
email
}
}
}
but the mutation will always return:
{
_id: 'blah',
email: 'blah',
partner: null
}
EXPECTATION:
partner
should not be null, it should be the latest updated value.