Find document by property and identity

Hey, I’m trying to figure out the best way of querying a document by one of it’s properties and the user identity. Seems like it should be pretty straight forward but i can’t find a solution to it in the forum.

I’ve had success with the below for all users:

type Query {
  findPlanByDate(week: String!): Plan
}

But as soon as I update read access permission to the default FQL statement (which I kinda hoped would just work)

Lambda("terms", Equals(
  Var("terms"),
  [Identity()],
))

It complain about Insufficient privileges.

FYI I’m new to Fauna and GraphQL for that matter.

Thanks!

Hi @2Steaks and welcome!

Would you provide me with more details? What do you pass as terms to the Lambda() function?

Luigi

Hi, so the schema automatically generates the index

{
  name: "findPlanByDate",
  unique: false,
  serialized: true,
  source: "Plan",
  terms: [
    {
      field: ["data", "week"]
    }
  ]
}

I’m already able to CRUD for an authenticated user so that they can only query/mutate their own documents, but I can’t get the index to work in the same manner.

Perhaps I should be querying the user to retrieve the plan via it’s relationship?

type User {
  plans: [Plan!] @relation
}

type Plan {
  week: String!
  owner: User!
}

Hi @2Steaks,

Are yiu using ABAC for authenticating users?

Luigi

I am yes, but I’ve managed to fix it. I had given my resolver and index the same name and so I could not apply permissions correctly.