Repository navigation
index.Function.createSubjects
function createSubjects<TMap>(): <T>(map) => T;Defined in: packages/graphql-casl/src/subjects.ts:82
Returns a helper that validates a subject-name const object against the keys
of TMap.
TMap extends Record<string, object>
The subject map, e.g. SubjectMap<Resolvers, ResolversTypes>.
A function that returns the object it is given.
<T>(map) => T
Use subjectsOf, which needs no object and stays in step
with the schema on its own. This restates names TMap already carries, so
every type added to the schema has to be listed here too — interfaces and
unions included — before anything compiles again. It keeps working and is not
scheduled for removal.
The object's keys must exactly cover the derived domain type names — TypeScript errors if any are missing or misspelled. Values equal keys so each entry can be used directly in CASL calls.
const Subject = createSubjects<AppSubjectMap>()({
User: 'User', Note: 'Note', Org: 'Org', OrgMember: 'OrgMember',
} as const);
ability.can('read', Subject.User); // typed literal 'User', not plain string