npm.io
1.1.0 • Published 3 years ago

@arquivei/codegen

Licence
MIT
Version
1.1.0
Deps
6
Size
14 kB
Vulns
0
Weekly
0

@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:

Install package in dev dependencies

❯ yarn add -D @arquivei/codegen

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',
    },
  },
});

Add script in your package.json

"scripts": {
  "gen:types": "graphql-codegen",
}

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' Set your current environment. E.g: frontend-saas the value is 'client' and graphql-saas is bff
options.schema string Set schema location, glob files or URL
options.token string If the server (BFF) has authentication
options.documents string If you use plugins that generate code for the client-side
options.config object Config codegen plugins
options.outputFile string File and path to sabe generated type files
options.extraPlugins string[] If you need add some extra plugins

Keywords