Hello,
I have been trying to apply different kind of authorization rules on entity fields :
schema sample:
type User {
id: ID! @id(autogenerate: true)
fullName: String!
createdEvents: [Event!]! @relationship(type: "CREATED_EVENT", direction: OUT)
savedEvents: [Event!]! @relationship(type: "SAVED_EVENT", direction: OUT)
}
type Category {
name: String! @id(autogenerate: false)
interests: [Interest!]! @relationship(type: "INTEREST_OF", direction: IN)
}
type Interest{
name: String! @id(autogenerate: false)
category: Category! @relationship(type: "INTEREST_OF", direction: OUT)
}
type Event {
id: ID! @id(autogenerate: true)
name: String!
startDate: DateTime!
endDate: DateTime!
createdBy: User! @relationship(type: "CREATED_EVENT", direction: IN)
usersSaved: [User!]! @relationship(type: "SAVED_EVENT", direction: IN)
interests: [Interest!]! @relationship(type: "INTEREST_IN", direction: OUT)
}
As shown above, What i want to do is that,
-
createdBy field of the the entity
Eventmust be immutable and must not be modified after it has been set on creation time. -
usersSaved field of the entity
Eventcan be modified by any user i.e any user can connect to the event through this field. -
interests and Other fields left of the entity
Eventcan only be modified by the creator user (the one the createdBy field refers to).
I have attempted to apply auth rules on each field but @relationship and @auth can’t be used together. Where as Entity/Object level @auth directive can’t be specific enough to protect the interests field not to be modified by other users other than the creator and allow usersSaved to be modified by anyone(any user).
I have also attempted to use @readonly directive on the createdBy field but the same issue gets raised as the above.
I would really appreciate any help, workaround or ideas regarding this. Thank you.