Hi,
I’m trying to learn how faunadb works, and I’m looking for a way to debug what is going on in my UDFs, privilege functions, etc.
I’m trying to debug my “create” privilege function. I’m using graphql, and my schema looks like this:
type User {
email: String! @unique
company: Company!
}
type Company {
name: String! @unique
users: [User!]! @relation
}
When a new user registers, I want them to create the user, and then create a new company, with the new user associated, but I want to make sure users can only create companies with themselves associated, and then I plan to build out the other rules so only company users can edit / delete / read their own company as well. The user gets created just fine, but when I try and create the new company, I run into permission issues.
My graphql mutation looks like this:
variables = {
data: {
name: "foo",
users: {
connect: [userId], //this is the newly created user id
},
},
}
mutation createCompany($data: CompanyInput!) {
createCompany(data: $data) {
_id
name
}
}
and the role privileges looks like this:
{
resource: Collection("Company"),
actions: {
read: true,
write: true,
create: Query(
Lambda(
"values",
ContainsValue(Identity(), Select(["data", "users"], Var("values")))
)
),
delete: true,
history_read: false,
history_write: false,
unrestricted_read: false
}
},
I’ve tried Equals(Identity(), Select([“data”, “users”], Var(“values”)))
and I’ve tried ContainsValue(Identity(), Select([“data”, “users”, “connect”], Var(“values”)))
nothing seems to work, and I can’t tell what’s going on. Currently, I’m just messing around with trial and error, so my real question is, can I output the value of “data” that gets passed to the lambda somehow so i can see what’s getting passed into the lambda when the mutation is executed? That way I could at least dump it to the shell and play around there.