1.0.4 • Published 3 days ago

@toptal/davinci-graphql-codegen-extensions v1.0.4

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
3 days ago

@toptal/davinci-graphql-codegen-extensions

A collection of extensions for the Graphql Code Generator.

The currently available extensions:

  • Schema loader - preprocessor for GQL schema that filters out enum values hidden from the consumers
  • Enums plugin - a plugin that generates a type for a mapping object between enum and the target type; by default all the enum values are required to be specified in the object, values that are marked with a special annotation become optional

Usage

Schema loader

The back-end can mark a new enum value as hidden with tt_earlySupportHidden directive.

enum StatusEnum {
  ACTIVE
  INACTIVE
  PENDING @tt_earlySupportHidden
}

Such annotated values will be removed from the schema used for types generation and won't be included in the Typescript enum.

Installation

Configure your schema to use @toptal/davinci-graphql-codegen-extensions/schema-loader loader:

schema:
  - schema.graphql
      loader: @toptal/davinci-graphql-codegen-extensions/schema-loader
documents: ./src/**/*.graphql
generates:
  ./src/types.ts:
    plugins:
      - typescript
      - typescript-operations

This will ensure that enum values with @HIDDEN

Enums plugin

The back-end can mark a new enum value as optional with tt_earlySupport directive.

enum StatusEnum {
  ACTIVE
  INACTIVE
  PENDING @tt_earlySupport
}
Installation

Add @toptal/davinci-graphql-codegen-extensions/enums-plugin plugin to your configuration:

schema: schema.graphql
documents: ./src/**/*.graphql
generates:
  ./src/types.ts:
    plugins:
      - typescript
      - @toptal/davinci-graphql-codegen-extensions/enums-plugin
1.0.4

6 months ago

1.0.3

10 months ago

1.0.2

2 years ago

1.0.1

2 years ago