schema

package
v0.0.0-...-08ddf37 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2017 License: ISC Imports: 5 Imported by: 6

Documentation

Overview

Package schema provides the ability to register objects to be exposed via a graphql api.

Schema self-registers and provides the 'schema' root field that lists the available root fields and other introspection data.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GraphQLFieldFunc

type GraphQLFieldFunc func(context.Context, resolver.Resolver, *graphql.Field) (interface{}, error)

GraphQLFieldFunc is the type that can generate a response from a graphql.Field.

type GraphQLFieldSpec

type GraphQLFieldSpec struct {
	Name        string
	Description string
	Func        GraphQLFieldFunc
	Arguments   []graphql.Argument // Describes any arguments the field accepts
	IsRoot      bool               // If true, this field should be exposed at the root of the GraphQL schema

}

GraphQLFieldSpec describes a field associated with a type in a GraphQL schema.

func (*GraphQLFieldSpec) GraphQLTypeInfo

func (g *GraphQLFieldSpec) GraphQLTypeInfo() GraphQLTypeInfo

type GraphQLFieldSpecMap

type GraphQLFieldSpecMap map[string]*GraphQLFieldSpec

func (GraphQLFieldSpecMap) GraphQLTypeInfo

func (g GraphQLFieldSpecMap) GraphQLTypeInfo() GraphQLTypeInfo

type GraphQLType

type GraphQLType interface {
	GraphQLTypeInfo() GraphQLTypeInfo
}

GraphQLType is the interface that all GraphQL types satisfy

type GraphQLTypeInfo

type GraphQLTypeInfo struct {
	Name        string
	Description string
	Fields      GraphQLFieldSpecMap
}

func WithIntrospectionField

func WithIntrospectionField(typeInfo GraphQLTypeInfo) GraphQLTypeInfo

func (GraphQLTypeInfo) GraphQLTypeInfo

func (g GraphQLTypeInfo) GraphQLTypeInfo() GraphQLTypeInfo

type GraphQLTypeIntrospector

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

func (*GraphQLTypeIntrospector) GraphQLTypeInfo

func (i *GraphQLTypeIntrospector) GraphQLTypeInfo() GraphQLTypeInfo

type Schema

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

Schema represents the registered types that know how to respond to root fields.

Example
package main

import (
	"encoding/json"
	"fmt"

	"github.com/tmc/graphql/executor"
	"github.com/tmc/graphql/parser"
	"github.com/tmc/graphql/schema"
	"golang.org/x/net/context"
)

func main() {
	s := schema.New()
	call, err := parser.ParseOperation([]byte(`{__schema{root_fields{name}}}`))
	if err != nil {
		fmt.Println(err)
	}
	executor := executor.New(s)
	result, err := executor.HandleOperation(context.Background(), call)
	if err != nil {
		fmt.Println(err)
	}
	asjson, _ := json.MarshalIndent(result, "", " ")
	fmt.Println(string(asjson))
}
Output:

[
 {
  "root_fields": [
   {
    "name": "__schema"
   },
   {
    "name": "__type"
   }
  ]
 }
]

func New

func New() *Schema

New prepares a new Schema.

func (*Schema) GetTypeInfo

func (s *Schema) GetTypeInfo(o GraphQLType) GraphQLTypeInfo

func (*Schema) GraphQLTypeInfo

func (s *Schema) GraphQLTypeInfo() GraphQLTypeInfo

func (*Schema) Register

func (s *Schema) Register(t GraphQLType)

Register registers a new type

func (*Schema) RegisteredTypes

func (s *Schema) RegisteredTypes() map[string]GraphQLTypeInfo

func (*Schema) RootFields

func (s *Schema) RootFields() map[string]*GraphQLFieldSpec

Jump to

Keyboard shortcuts

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