compiler

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: MIT Imports: 8 Imported by: 2

README

GoDoc Go Report Card Build Status codecov

GraphQL Compiler Internals

Package compiler provides types and interfaces for interacting with or implementing a compiler for the GraphQL IDL.

Features

  • Import Tree Reduction
  • Type Validation
  • Type Merging
Import Tree Reduction

GraphQL documents can import one another with the following directive:

directive @import(paths: [String]!) on DOCUMENT
Type Validation

Type Validation/Checking is provided by implementing the TypeChecker interface. The Validate function is a TypeChecker that enforces type validation, per the GraphQL spec.

Type Merging

Type merging handles merging type extensions with their original type definition.

Documentation

Overview

Package compiler provides utilities for working with GraphQL documents.

Index

Constants

This section is empty.

Variables

View Source
var ImportValidator = TypeCheckerFn(validateImports)

ImportValidator validates that all types are correctly imported.

View Source
var Types []*ast.TypeDecl

Types contains the builtin types provided by the compiler and any custom types given to RegisterTypes.

Functions

func CheckTypes

func CheckTypes(docs IR, checkers ...TypeChecker) (errs []error)

CheckTypes is a helper function for running a suite of type checking on several GraphQL Documents. Any types given to RegisterTypes will included as their very own document.

func FromIR

func FromIR(ir IR) []*ast.Document

FromIR converts the compiler intermediate representation back to a simple slice of GraphQL Documents.

func Lookup

func Lookup(name string, ir IR) (*ast.Document, []*ast.TypeDecl)

Lookup returns the Type and the Document it belongs to, or nil.

func MergeExtensions

func MergeExtensions(types map[string][]*ast.TypeDecl) map[string][]*ast.TypeDecl

MergeExtensions merges type extensions with their original declaration.

func RegisterTypes

func RegisterTypes(decls ...*ast.TypeDecl)

RegisterTypes registers pre-defined types with the compiler.

func TestTypeChecker

func TestTypeChecker(t tester, v TypeChecker)

TestTypeChecker implements a few tests for custom type checkers. It is mainly focused around ensuring validation across imports.

Types

type IR

type IR map[*ast.Document]map[string][]*ast.TypeDecl

IR is a representation used by the compiler APIs.

func ReduceImports

func ReduceImports(docs IR) (IR, error)

ReduceImports reduces a set of Documents by including imported type defs into the Documents that they're imported into.

To import a Document the @import directive is used: directive @import(paths: [String]) on DOCUMENT

func ToIR

func ToIR(docs []*ast.Document) IR

ToIR converts a GraphQL Document to a intermediate representation for the compiler internals.

type ImportError

type ImportError struct {
	Doc *ast.Document
	Msg string
}

ImportError represents an error with the imports in a GraphQL Document

func (*ImportError) Error

func (e *ImportError) Error() string

type TypeChecker

type TypeChecker interface {
	// Check performs type checking on the types in the IR.
	Check(ir IR) []error
}

TypeChecker represents type checking functionality for a GraphQL Document.

type TypeCheckerFn

type TypeCheckerFn func(IR) []error

TypeCheckerFn represents a single function behaving as a TypeChecker.

func (TypeCheckerFn) Check

func (f TypeCheckerFn) Check(ir IR) []error

Check calls the TypeCheckerFn given the GraphQL Document.

type TypeError

type TypeError struct {
	// Document where type error was discovered
	Doc *ast.Document

	// Type error message
	Msg string
}

TypeError represents a type error.

func (*TypeError) Error

func (e *TypeError) Error() string

Error returns a string representation of a TypeError.

Directories

Path Synopsis
Package spec provides the types and validator as defined by the GraphQL spec.
Package spec provides the types and validator as defined by the GraphQL spec.

Jump to

Keyboard shortcuts

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