Skip to content
This repository was archived by the owner on Oct 17, 2020. It is now read-only.

Files

Latest commit

8f0b44c · Aug 23, 2018

History

History
141 lines (99 loc) · 4.35 KB

03-Generator-CLIs.md

File metadata and controls

141 lines (99 loc) · 4.35 KB

Generator CLIs

graphql-binding

The graphql-binding generator CLI is used for code generation (codegen) in the context of GraphQL bindings. It can for example be used to generate TypeScript type definitions for your bindings.

Install

Install with npm:

npm install -g graphql-binding

OR

Install with yarn:

yarn global add graphql-binding

Usage

Usage: graphql-binding -i [input] -l [language] -b [outputBinding]

Options:
  --help                Show help                                      [boolean]
  --version             Show version number                            [boolean]
  --input, -i           Path to schema.js or schema.ts file            [string] [required]
  --language, -l        Language of the generator. Available languages:
                        typescript, javascript                         [string] [required]
  --outputBinding, -b   Output binding. Example: binding.ts            [string] [required]
  --outputTypedefs, -t  Output type defs. Example: typeDefs.graphql    [string]

Generating a Binding

We're going to generate a GraphQL binding for the following schema.

graphql-binding --input ./src/schema.js --language javascript --outputBinding binding.js

This will create a GraphQL Binding like this

Generating Type Definitions

We can add the --outputTypedefs flag to our command to output type definitions in a .graphql file.

graphql-binding --input ./src/schema.js --language javascript --outputBinding binding.js --outputTypedefs typeDefs.graphql

This will create a typeDefs.graphql.

Usage with GraphQL Config

The graphql-binding CLI integrates with GraphQL Config. This means instead of passing arguments to the command, you can write a .graphqlconfig.yml file which will be read by the CLI.

For example, consider the following .graphqlconfig.yml:

projects:
  myapp:
    schemaPath: schema.graphql
    extensions:
      codegen:
        - generator: graphql-binding
          language: typescript
          input: schema.js
          output:
            binding: mybinding.ts

Invoking graphql codegen in a directory where the above .graphqlconfig is available is equivalent to invoking the following terminal command:

graphql-binding --language typescript --input schema.js --outputBinding mybinding.ts

prisma-binding

Install

Install with npm:

npm install -g prisma-binding

OR

Install with yarn:

yarn global add prisma-binding

Usage

Usage: prisma-binding -i [input] -l [language] -b [outputBinding]

Options:
  --help                Show help                                      [boolean]
  --version             Show version number                            [boolean]
  --input, -i           Path to prisma.graphql file                    [string] [required]
  --language, -l        Language of the generator. Available languages:
                        typescript, javascript                         [string] [required]
  --outputBinding, -b   Output binding. Example: binding.ts            [string] [required]

Usage with GraphQL Config

The prisma-binding CLI integrates with GraphQL Config. This means instead of passing arguments to the command, you can write a .graphqlconfig.yml file which will be read by the CLI.

For example, consider the following .graphqlconfig.yml:

projects:
  myapp:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: prisma/prisma.yml
      codegen:
        - generator: prisma-binding
          language: typescript
          output:
            binding: src/generated/prisma.ts

Invoking simply graphql codegen in a directory where the above .graphqlconfig is available is equivalent to invoking the following terminal command:

prisma-binding --language typescript --outputBinding mybinding.ts

Writing your own generator CLI

If you're adding custom functionality to your GraphQL binding, you'll need to build a custom generator CLI for it.