1.1.0 • Published 10 months ago

@arquivei/codegen v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@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

nametyperequireddescription
environment'client' \| 'bff':heavy_check_mark:Set your current environment. E.g: frontend-saas the value is 'client' and graphql-saas is bff
options.schemastring:heavy_check_mark:Set schema location, glob files or URL
options.tokenstring:x:If the server (BFF) has authentication
options.documentsstring:x:If you use plugins that generate code for the client-side
options.configobject:x:Config codegen plugins
options.outputFilestring:x:File and path to sabe generated type files
options.extraPluginsstring[]:x:If you need add some extra plugins