@arquivei/codegen
v1.1.0
Published
Codegen rules designed by Arquivei
Downloads
1,181
Maintainers
Readme
@arquivei/codegen
The @arquivei/codegen package aims to center all codegen rules from Typescript and GraphQL projects.
Usage
Check below step by step to use this package:
:one: Install package in dev dependencies
❯ yarn add -D @arquivei/codegen
:two: Create codegen.js
and configure according to your need
Using in client-side:
const codegenConfig = require('@arquivei/codegen').default;
module.exports = codegenConfig({
environment: 'client',
options: {
schema: "http://localhost:5000/graphql", // BFF url
token: `Bearer TOKEN`, // non required, check if need
config: {
skipTypename: true,
useTypeImports: true,
documentMode: 'external',
},
},
});
Using in BFF (server-side):
const codegenConfig = require('@arquivei/codegen').default;
module.exports = codegenConfig({
environment: 'bff',
options: {
schema: './src/core/schema/*.graphql',
config: {
skipTypename: true,
useTypeImports: true,
contextType: '.#Context',
},
},
});
:three: Add script in your package.json
"scripts": {
"gen:types": "graphql-codegen",
}
:four: Run the script
❯ yarn gen:types
OBS: if you're on client-side, be sure that BFF is up
Properties
| name | type | required | description |
|---|---|---|---|
| environment
| 'client' \| 'bff'
| :heavy_check_mark: | Set your current environment. E.g: frontend-saas
the value is 'client'
and graphql-saas
is bff
|
| options.schema
| string
| :heavy_check_mark: | Set schema location, glob files or URL |
| options.token
| string
| :x: | If the server (BFF) has authentication |
| options.documents
| string
| :x: | If you use plugins that generate code for the client-side |
| options.config
| object
| :x: | Config codegen plugins |
| options.outputFile
| string
| :x: | File and path to sabe generated type files |
| options.extraPlugins
| string[]
| :x: | If you need add some extra plugins |