starwars

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2018 License: MIT Imports: 14 Imported by: 0

README

starwars example

This server demonstrates a few advanced features of graphql:

  • connections
  • unions
  • interfaces
  • enums

to run this server

go run ./example/starwars/server/server.go

and open http://localhost:8080 in your browser

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewExecutableSchema

func NewExecutableSchema(cfg Config) graphql.ExecutableSchema

NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.

Types

type Character

type Character interface {
	IsCharacter()
}

type CharacterFields

type CharacterFields struct {
	ID        string
	Name      string
	FriendIds []string
	AppearsIn []Episode
}

type ComplexityRoot added in v0.5.0

type ComplexityRoot struct {
	Droid struct {
		Id                func(childComplexity int) int
		Name              func(childComplexity int) int
		Friends           func(childComplexity int) int
		FriendsConnection func(childComplexity int, first *int, after *string) int
		AppearsIn         func(childComplexity int) int
		PrimaryFunction   func(childComplexity int) int
	}

	FriendsConnection struct {
		TotalCount func(childComplexity int) int
		Edges      func(childComplexity int) int
		Friends    func(childComplexity int) int
		PageInfo   func(childComplexity int) int
	}

	FriendsEdge struct {
		Cursor func(childComplexity int) int
		Node   func(childComplexity int) int
	}

	Human struct {
		Id                func(childComplexity int) int
		Name              func(childComplexity int) int
		Height            func(childComplexity int, unit LengthUnit) int
		Mass              func(childComplexity int) int
		Friends           func(childComplexity int) int
		FriendsConnection func(childComplexity int, first *int, after *string) int
		AppearsIn         func(childComplexity int) int
		Starships         func(childComplexity int) int
	}

	Mutation struct {
		CreateReview func(childComplexity int, episode Episode, review Review) int
	}

	PageInfo struct {
		StartCursor func(childComplexity int) int
		EndCursor   func(childComplexity int) int
		HasNextPage func(childComplexity int) int
	}

	Query struct {
		Hero      func(childComplexity int, episode *Episode) int
		Reviews   func(childComplexity int, episode Episode, since *time.Time) int
		Search    func(childComplexity int, text string) int
		Character func(childComplexity int, id string) int
		Droid     func(childComplexity int, id string) int
		Human     func(childComplexity int, id string) int
		Starship  func(childComplexity int, id string) int
	}

	Review struct {
		Stars      func(childComplexity int) int
		Commentary func(childComplexity int) int
		Time       func(childComplexity int) int
	}

	Starship struct {
		Id      func(childComplexity int) int
		Name    func(childComplexity int) int
		Length  func(childComplexity int, unit *LengthUnit) int
		History func(childComplexity int) int
	}
}

type Config

type Config struct {
	Resolvers  ResolverRoot
	Directives DirectiveRoot
	Complexity ComplexityRoot
}

func NewResolver

func NewResolver() Config

type DirectiveRoot

type DirectiveRoot struct {
}

type Droid

type Droid struct {
	CharacterFields
	PrimaryFunction string
}

func (Droid) IsCharacter added in v0.6.0

func (Droid) IsCharacter()

func (Droid) IsSearchResult added in v0.6.0

func (Droid) IsSearchResult()

type DroidResolver

type DroidResolver interface {
	Friends(ctx context.Context, obj *Droid) ([]Character, error)
	FriendsConnection(ctx context.Context, obj *Droid, first *int, after *string) (FriendsConnection, error)
}

type Episode

type Episode string
const (
	EpisodeNewhope Episode = "NEWHOPE"
	EpisodeEmpire  Episode = "EMPIRE"
	EpisodeJedi    Episode = "JEDI"
)

func (Episode) IsValid

func (e Episode) IsValid() bool

func (Episode) MarshalGQL

func (e Episode) MarshalGQL(w io.Writer)

func (Episode) String

func (e Episode) String() string

func (*Episode) UnmarshalGQL

func (e *Episode) UnmarshalGQL(v interface{}) error

type FriendsConnection

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

func (*FriendsConnection) PageInfo

func (f *FriendsConnection) PageInfo() PageInfo

func (*FriendsConnection) TotalCount

func (f *FriendsConnection) TotalCount() int

type FriendsConnectionResolver

type FriendsConnectionResolver interface {
	Edges(ctx context.Context, obj *FriendsConnection) ([]FriendsEdge, error)
	Friends(ctx context.Context, obj *FriendsConnection) ([]Character, error)
}

type FriendsEdge

type FriendsEdge struct {
	Cursor string    `json:"cursor"`
	Node   Character `json:"node"`
}

type Human

type Human struct {
	CharacterFields
	StarshipIds []string

	Mass float64
	// contains filtered or unexported fields
}

func (*Human) Height

func (h *Human) Height(unit LengthUnit) float64

func (Human) IsCharacter added in v0.6.0

func (Human) IsCharacter()

func (Human) IsSearchResult added in v0.6.0

func (Human) IsSearchResult()

type HumanResolver

type HumanResolver interface {
	Friends(ctx context.Context, obj *Human) ([]Character, error)
	FriendsConnection(ctx context.Context, obj *Human, first *int, after *string) (FriendsConnection, error)

	Starships(ctx context.Context, obj *Human) ([]Starship, error)
}

type LengthUnit

type LengthUnit string
const (
	LengthUnitMeter LengthUnit = "METER"
	LengthUnitFoot  LengthUnit = "FOOT"
)

func (LengthUnit) IsValid

func (e LengthUnit) IsValid() bool

func (LengthUnit) MarshalGQL

func (e LengthUnit) MarshalGQL(w io.Writer)

func (LengthUnit) String

func (e LengthUnit) String() string

func (*LengthUnit) UnmarshalGQL

func (e *LengthUnit) UnmarshalGQL(v interface{}) error

type MutationResolver

type MutationResolver interface {
	CreateReview(ctx context.Context, episode Episode, review Review) (*Review, error)
}

type PageInfo

type PageInfo struct {
	StartCursor string `json:"startCursor"`
	EndCursor   string `json:"endCursor"`
	HasNextPage bool   `json:"hasNextPage"`
}

type QueryResolver

type QueryResolver interface {
	Hero(ctx context.Context, episode *Episode) (Character, error)
	Reviews(ctx context.Context, episode Episode, since *time.Time) ([]Review, error)
	Search(ctx context.Context, text string) ([]SearchResult, error)
	Character(ctx context.Context, id string) (Character, error)
	Droid(ctx context.Context, id string) (*Droid, error)
	Human(ctx context.Context, id string) (*Human, error)
	Starship(ctx context.Context, id string) (*Starship, error)
}

type Resolver

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

func (*Resolver) Droid

func (r *Resolver) Droid() DroidResolver

func (*Resolver) FriendsConnection

func (r *Resolver) FriendsConnection() FriendsConnectionResolver

func (*Resolver) Human

func (r *Resolver) Human() HumanResolver

func (*Resolver) Mutation

func (r *Resolver) Mutation() MutationResolver

func (*Resolver) Query

func (r *Resolver) Query() QueryResolver

func (*Resolver) Starship

func (r *Resolver) Starship() StarshipResolver

type ResolverRoot

type ResolverRoot interface {
	Droid() DroidResolver
	FriendsConnection() FriendsConnectionResolver
	Human() HumanResolver
	Mutation() MutationResolver
	Query() QueryResolver
	Starship() StarshipResolver
}

type Review

type Review struct {
	Stars      int
	Commentary *string
	Time       time.Time
}

func UnmarshalReviewInput

func UnmarshalReviewInput(v interface{}) (Review, error)

type SearchResult

type SearchResult interface {
	IsSearchResult()
}

type Starship

type Starship struct {
	ID      string  `json:"id"`
	Name    string  `json:"name"`
	Length  float64 `json:"length"`
	History [][]int `json:"history"`
}

func (Starship) IsSearchResult added in v0.6.0

func (Starship) IsSearchResult()

type StarshipResolver

type StarshipResolver interface {
	Length(ctx context.Context, obj *Starship, unit *LengthUnit) (float64, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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