All the examples on this page are written for the following schema:
const typeDefs: string = ` |
Grant access to a Type
To allow anonymous users to view Posts
we first need to allow them to send a Query
to Post
(this is distinct from a Mutation
). And then we need to allow the fields on Post
, in this case all of them.
const policy: Policy = { |
Grant access to a single field on a Type
Sometimes you only want to allow access to certain fields, in this case title
. *This isn’t always the best idea, see the next example for blocking access.
const policy: Policy = { |
Grant access to a Type, except for a specific field
The previous example shows how to allow just a specific type, but it doesn’t block access. You could add another policy that allowed access to Post::*
and then the role would be able to see everything not just Post::title
.
If you want to stop a role from accessing a field you need to explicity deny it. Once a field or type has been explicitly denied, no other policy can allow it.
const policy: Policy = { |