Repository navigation
index.Interface.RequireCan
Defined in: packages/graphql-casl/src/createCan.ts:212
The rule builder returned by createCan when a buildSubject tagger
is provided.
Supports both bare-subject checks and condition checks where the subject
instance is built from resolver args via getSubjectData.
The subject name K narrows getSubjectData's return to that subject's fields
(Partial<TSubjectMap[K]>); annotate getSubjectData's args parameter with
your generated *Args type to type the extraction end to end.
getSubjectData also receives the resolver's parent, which is what a
field-level rule needs — "read User.email only when it is your own user" is a
condition on the parent User, not on the field's args. Annotate it with
ParentOf<UserResolvers['email']> to type it. See the caveat on
createCan about resolvers that project by selection set.
TSubjectMap extends Record<string, object>
The subject map, e.g. SubjectMap<Resolvers, ResolversTypes>.
RequireCan<K, TArgs, TParent>(
action,
subject,
getSubjectData?,
options?): CheckableRule;Defined in: packages/graphql-casl/src/createCan.ts:213
The rule builder returned by createCan when a buildSubject tagger
is provided.
K extends string
TArgs extends Record<string, unknown> = Record<string, unknown>
TParent = unknown
K
(args, parent) => Partial<TSubjectMap[K]>
Supports both bare-subject checks and condition checks where the subject
instance is built from resolver args via getSubjectData.
The subject name K narrows getSubjectData's return to that subject's fields
(Partial<TSubjectMap[K]>); annotate getSubjectData's args parameter with
your generated *Args type to type the extraction end to end.
getSubjectData also receives the resolver's parent, which is what a
field-level rule needs — "read User.email only when it is your own user" is a
condition on the parent User, not on the field's args. Annotate it with
ParentOf<UserResolvers['email']> to type it. See the caveat on
createCan about resolvers that project by selection set.
readonly fields: RequireCanFields<TSubjectMap>;Defined in: packages/graphql-casl/src/createCan.ts:237
Builds one rule that guards every field of a type, using CASL's field-level permissions.
readonly onResult: RequireCanOnResult<TSubjectMap>;Defined in: packages/graphql-casl/src/createCan.ts:229
Builds a rule that authorizes the resolved value instead of the args.