@vantreeseba/graphql-casl-codegen
v1.12.0
Published
GraphQL Code Generator plugin that emits @vantreeseba/graphql-casl subject bindings for your generated resolver types.
Maintainers
Readme
@vantreeseba/graphql-casl-codegen
A GraphQL Code Generator plugin that emits the
@vantreeseba/graphql-casl subject bindings for your generated
resolver types: the subject map, the subject names, the typed tagger and an ability builder. They derive
from the types in the same file, so there is no list of subjects to keep in step with the schema.
Install
npm install -D @vantreeseba/graphql-casl-codegen @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-resolvers
npm install @vantreeseba/graphql-casl @casl/ability graphql graphql-middlewareQuick start
List it after typescript and typescript-resolvers, in the same output file:
// codegen.ts
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: './schema.graphql',
generates: {
'src/permissions.generated.ts': {
plugins: ['typescript', 'typescript-resolvers', '@vantreeseba/graphql-casl-codegen'],
},
},
};
export default config;Run npx graphql-codegen, and the file ends with:
export type AppSubjectMap = SubjectMap<Resolvers, ResolversTypes>;
export const Subject = subjectsOf<AppSubjectMap>();
export const typed = createTyped<AppSubjectMap>();
export const ability = () => createGraphQLAbility<AppSubjectMap>();Documentation
- Install and configure, with every option
- Generated output, and using it with
createCan - Common mistakes
- Every export, as
llms.txt - Changelog
License
MIT © Benjamin Van Treese
