typegen

command
v0.33.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

README

typegen

Generate Golang types from GraphQL schema introspection

Getting Started

  1. Include typegen in your project as a tool / install in some fashion.

  2. Add a ./path/to/package/typegen.yaml configuration with the type you want generated:

    ---
    types:
      - name: MyGraphQLTypeName
      - name: AnotherTypeInGraphQL
        createAs: map[string]int
    
  3. Add a generation command inside the main.go (or equivalent)

    // Package CoolPackage provides cool stuff, based on generated types
    //go:generate ./path/to/typegen -p $GOPACKAGE
    package CoolPackage
    // ... implementation ...
    
  4. Run go generate

  5. Add the ./path/to/package/types.go file to your repo

Configuration

Command Flags

Flags for running the typegen command:

Flag Description
-p <Package Name> Package name used within the generated file. Overrides the configuration file.
-v Enable verbose logging

Per-package

Configuration on what types to generate, and any overrides from the schema exist within the package directory in a file named typegen.yaml. The file has a simple configuration format, and includes the following sections:

types

Types is a list of the types to explicitly generate. Any required sub-type will also be generated until we hit a Golang type.

Name Required Description
name Yes The name of the field to search for and create
package No Name of the package the output file will be part of (see -p flag)
createAs No If you want to override the type that is created, use this to explicitly name the type

ORDER MATTERS: Add types with overrides first, otherwise they might not get created as you expect. If A => B => gotype, and you want to override B, you must configure it first. If you configure A first, B will be generated as a dependency before we create B via configuration.

Example:

---
types:
  - name: TheName
    createAs: int
  - name: ComplexType
    createAs: map[string]interface{}
  - name: AnotherName
imports

Optional list of go imports so you can use non-standard types.

Example:

---
imports:
  - github.com/newrelic/newrelic-client-go/internal/serialization

types:
  - name: EpochMilliseconds
    createAs: serialization.EpochTime

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL