todo

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: MIT Imports: 14 Imported by: 0

README

todo app

This is the simplest example of a graphql server.

to run this server

go run ./example/todo/server/server.go

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllRole = []Role{
	RoleAdmin,
	RoleOwner,
}

Functions

func NewExecutableSchema

func NewExecutableSchema(cfg Config) graphql.ExecutableSchema

NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.

Types

type ComplexityRoot

type ComplexityRoot struct {
	MyMutation struct {
		CreateTodo func(childComplexity int, todo TodoInput) int
		UpdateTodo func(childComplexity int, id int, changes map[string]interface{}) int
	}

	MyQuery struct {
		LastTodo func(childComplexity int) int
		Todo     func(childComplexity int, id int) int
		Todos    func(childComplexity int) int
	}

	Todo struct {
		Done func(childComplexity int) int
		ID   func(childComplexity int) int
		Text func(childComplexity int) int
	}
}

type Config

type Config struct {
	Resolvers  ResolverRoot
	Directives DirectiveRoot
	Complexity ComplexityRoot
}

func New

func New() Config

type DirectiveRoot

type DirectiveRoot struct {
	HasRole func(ctx context.Context, obj interface{}, next graphql.Resolver, role Role) (res interface{}, err error)

	User func(ctx context.Context, obj interface{}, next graphql.Resolver, id int) (res interface{}, err error)
}

type MutationResolver

type MutationResolver resolvers

func (*MutationResolver) CreateTodo

func (r *MutationResolver) CreateTodo(ctx context.Context, todo TodoInput) (*Todo, error)

func (*MutationResolver) UpdateTodo

func (r *MutationResolver) UpdateTodo(ctx context.Context, id int, changes map[string]interface{}) (*Todo, error)

type MyMutationResolver

type MyMutationResolver interface {
	CreateTodo(ctx context.Context, todo TodoInput) (*Todo, error)
	UpdateTodo(ctx context.Context, id int, changes map[string]interface{}) (*Todo, error)
}

type MyQueryResolver

type MyQueryResolver interface {
	Todo(ctx context.Context, id int) (*Todo, error)
	LastTodo(ctx context.Context) (*Todo, error)
	Todos(ctx context.Context) ([]*Todo, error)
}

type Ownable

type Ownable interface {
	Owner() *User
}

type QueryResolver

type QueryResolver resolvers

func (*QueryResolver) LastTodo

func (r *QueryResolver) LastTodo(ctx context.Context) (*Todo, error)

func (*QueryResolver) Todo

func (r *QueryResolver) Todo(ctx context.Context, id int) (*Todo, error)

func (*QueryResolver) Todos

func (r *QueryResolver) Todos(ctx context.Context) ([]*Todo, error)

type ResolverRoot

type ResolverRoot interface {
	MyMutation() MyMutationResolver
	MyQuery() MyQueryResolver
}

type Role

type Role string
const (
	RoleAdmin Role = "ADMIN"
	RoleOwner Role = "OWNER"
)

func (Role) IsValid

func (e Role) IsValid() bool

func (Role) MarshalGQL

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

func (Role) String

func (e Role) String() string

func (*Role) UnmarshalGQL

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

type Todo

type Todo struct {
	ID   int
	Text string
	Done bool
	// contains filtered or unexported fields
}

func (Todo) Owner

func (t Todo) Owner() *User

type TodoInput

type TodoInput struct {
	// The body text
	Text string `json:"text"`
	// Is it done already?
	Done *bool `json:"done"`
}

Passed to createTodo to create a new todo

type User

type User struct {
	ID   int
	Name string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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