generator

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPackageName = "schema"

DefaultPackageName refers to default name given to resulting package.

View Source
const GeneratedFileExt = ".gql.go"

GeneratedFileExt describes the default extension used when the resulting Go file is written.

View Source
const GraphQLFileExt = ".graphql"

GraphQLFileExt refers to extension used by GraphQL schema definition files.

View Source
const (
	MissingNamedDirectiveErr = `extend keyword must be followed by @named directive`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DryRun

type DryRun struct {
	Debug bool
}

DryRun implements Saver interface, omits writing code to disk and logs result of render.

func (*DryRun) Save

func (d *DryRun) Save(name string, f *jen.File) error

Save runs render and logs results

type Generator

type Generator struct {
	// Saver handles rendering and persisting generators output.
	Saver

	// Invoker field identifies the caller that invoked generated. Name is
	// included in warning comment at top of generated file.
	Invoker string

	// PackageName of given to resulting files. Defaults to "schema."
	PackageName string
	// contains filtered or unexported fields
}

Generator generates Go code for type defnitions found in given source files.

func New

func New(source GraphQLFiles) Generator

New returns new generator given path and name of package resulting file will reside.

func (Generator) Run

func (g Generator) Run() error

Run generates code and saves

type GraphQLFile

type GraphQLFile struct {
	// contains filtered or unexported fields
}

GraphQLFile encapsulates parsed document and filepath.

func ParseFile

func ParseFile(path string) (*GraphQLFile, error)

ParseFile parses given path to GraphQL file returning parsed AST and error if any occurred while parsing.

func (*GraphQLFile) Definitions

func (file *GraphQLFile) Definitions() []ast.Node

Definitions returns all definition nodes found in document root.

func (*GraphQLFile) Filename

func (file *GraphQLFile) Filename() string

Filename returns the file's name

func (*GraphQLFile) Validate

func (file *GraphQLFile) Validate() error

Validate returns an error if given file does not appear to be GraphQL Schema Definition Language (SDL).

type GraphQLFiles

type GraphQLFiles []*GraphQLFile

GraphQLFiles encapsulates parsed document and filepath.

func ParseDir

func ParseDir(path string) (GraphQLFiles, error)

ParseDir parses all files in given path returning parsed AST and error if any occurred while parsing or given path is not valid.

func (GraphQLFiles) Definitions

func (files GraphQLFiles) Definitions() []ast.Node

Definitions returns all definition nodes found in document root.

func (GraphQLFiles) DefinitionsMap

func (files GraphQLFiles) DefinitionsMap() map[string]ast.Node

DefinitionsMap returns all definition nodes found in document root mapped by name.

func (GraphQLFiles) Dir

func (files GraphQLFiles) Dir() string

Dir returns path of where files can be found.

func (GraphQLFiles) Validate

func (files GraphQLFiles) Validate() error

Validate returns an error if given files does not appear to describe a GraphQL Schema.

type Saver

type Saver interface {
	Save(name string, f *jen.File) error
}

Saver represents an item that can write generated types.

Jump to

Keyboard shortcuts

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