dataloader

package
v0.0.0-...-c52f24a Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2018 License: MIT Imports: 13 Imported by: 0

README

dataloader

This example uses dataloaden to avoiding n+1 queries.

There is also nicksrandall/dataloader if you wanted to avoid doing more codegeneration.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoaderMiddleware

func LoaderMiddleware(next http.Handler) http.Handler

func MakeExecutableSchema

func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema

MakeExecutableSchema creates an ExecutableSchema from the Resolvers interface.

func NewExecutableSchema

func NewExecutableSchema(resolvers ResolverRoot) graphql.ExecutableSchema

NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.

Types

type Address

type Address struct {
	ID      int    `json:"id"`
	Street  string `json:"street"`
	Country string `json:"country"`
}

type AddressLoader

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

AddressLoader batches and caches requests

func (*AddressLoader) Clear

func (l *AddressLoader) Clear(key int)

Clear the value at key from the cache, if it exists

func (*AddressLoader) Load

func (l *AddressLoader) Load(key int) (*Address, error)

Load a address by key, batching and caching will be applied automatically

func (*AddressLoader) LoadAll

func (l *AddressLoader) LoadAll(keys []int) ([]*Address, []error)

LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured

func (*AddressLoader) LoadThunk

func (l *AddressLoader) LoadThunk(key int) func() (*Address, error)

LoadThunk returns a function that when called will block waiting for a address. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

func (*AddressLoader) Prime

func (l *AddressLoader) Prime(key int, value *Address) bool

Prime the cache with the provided key and value. If the key already exists, no change is made and false is returned. (To forcefully prime the cache, clear the key first with loader.clear(key).prime(key, value).)

type Customer

type Customer struct {
	ID        int    `json:"id"`
	Name      string `json:"name"`
	AddressID int
}

type CustomerResolver

type CustomerResolver interface {
	Address(ctx context.Context, obj *Customer) (*Address, error)
	Orders(ctx context.Context, obj *Customer) ([]Order, error)
}

type Item

type Item struct {
	Name string `json:"name"`
}

type ItemSliceLoader

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

ItemSliceLoader batches and caches requests

func (*ItemSliceLoader) Clear

func (l *ItemSliceLoader) Clear(key int)

Clear the value at key from the cache, if it exists

func (*ItemSliceLoader) Load

func (l *ItemSliceLoader) Load(key int) ([]Item, error)

Load a item by key, batching and caching will be applied automatically

func (*ItemSliceLoader) LoadAll

func (l *ItemSliceLoader) LoadAll(keys []int) ([][]Item, []error)

LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured

func (*ItemSliceLoader) LoadThunk

func (l *ItemSliceLoader) LoadThunk(key int) func() ([]Item, error)

LoadThunk returns a function that when called will block waiting for a item. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

func (*ItemSliceLoader) Prime

func (l *ItemSliceLoader) Prime(key int, value []Item) bool

Prime the cache with the provided key and value. If the key already exists, no change is made and false is returned. (To forcefully prime the cache, clear the key first with loader.clear(key).prime(key, value).)

type Order

type Order struct {
	ID     int       `json:"id"`
	Date   time.Time `json:"date"`
	Amount float64   `json:"amount"`
}

type OrderResolver

type OrderResolver interface {
	Items(ctx context.Context, obj *Order) ([]Item, error)
}

type OrderSliceLoader

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

OrderSliceLoader batches and caches requests

func (*OrderSliceLoader) Clear

func (l *OrderSliceLoader) Clear(key int)

Clear the value at key from the cache, if it exists

func (*OrderSliceLoader) Load

func (l *OrderSliceLoader) Load(key int) ([]Order, error)

Load a order by key, batching and caching will be applied automatically

func (*OrderSliceLoader) LoadAll

func (l *OrderSliceLoader) LoadAll(keys []int) ([][]Order, []error)

LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured

func (*OrderSliceLoader) LoadThunk

func (l *OrderSliceLoader) LoadThunk(key int) func() ([]Order, error)

LoadThunk returns a function that when called will block waiting for a order. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

func (*OrderSliceLoader) Prime

func (l *OrderSliceLoader) Prime(key int, value []Order) bool

Prime the cache with the provided key and value. If the key already exists, no change is made and false is returned. (To forcefully prime the cache, clear the key first with loader.clear(key).prime(key, value).)

type QueryResolver

type QueryResolver interface {
	Customers(ctx context.Context) ([]Customer, error)
	Torture(ctx context.Context, customerIds [][]int) ([][]Customer, error)
}

type Resolver

type Resolver struct{}

func (*Resolver) Customer_address

func (r *Resolver) Customer_address(ctx context.Context, it *Customer) (*Address, error)

func (*Resolver) Customer_orders

func (r *Resolver) Customer_orders(ctx context.Context, it *Customer) ([]Order, error)

func (*Resolver) Order_items

func (r *Resolver) Order_items(ctx context.Context, it *Order) ([]Item, error)

func (*Resolver) Query_customers

func (r *Resolver) Query_customers(ctx context.Context) ([]Customer, error)

func (*Resolver) Query_torture

func (r *Resolver) Query_torture(ctx context.Context, customerIds [][]int) ([][]Customer, error)

this method is here to test code generation of nested arrays

type ResolverRoot

type ResolverRoot interface {
	Customer() CustomerResolver
	Order() OrderResolver
	Query() QueryResolver
}

type Resolvers

type Resolvers interface {
	Customer_address(ctx context.Context, obj *Customer) (*Address, error)
	Customer_orders(ctx context.Context, obj *Customer) ([]Order, error)

	Order_items(ctx context.Context, obj *Order) ([]Item, error)
	Query_customers(ctx context.Context) ([]Customer, error)
	Query_torture(ctx context.Context, customerIds [][]int) ([][]Customer, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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