gqlgen: github.com/99designs/gqlgen/example/dataloader Index | Files | Directories

package dataloader

import "github.com/99designs/gqlgen/example/dataloader"

Index

Package Files

addressloader_gen.go dataloaders.go generated.go itemsliceloader_gen.go models_gen.go ordersliceloader_gen.go resolvers.go

func LoaderMiddleware Uses

func LoaderMiddleware(next http.Handler) http.Handler

nolint: gosec

func NewExecutableSchema Uses

func NewExecutableSchema(cfg Config) graphql.ExecutableSchema

NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.

type Address Uses

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

type AddressLoader Uses

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

AddressLoader batches and caches requests

func NewAddressLoader Uses

func NewAddressLoader(config AddressLoaderConfig) *AddressLoader

NewAddressLoader creates a new AddressLoader given a fetch, wait, and maxBatch

func (*AddressLoader) Clear Uses

func (l *AddressLoader) Clear(key int)

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

func (*AddressLoader) Load Uses

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

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

func (*AddressLoader) LoadAll Uses

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) LoadAllThunk Uses

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

LoadAllThunk returns a function that when called will block waiting for a Addresss. 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) LoadThunk Uses

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 Uses

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 AddressLoaderConfig Uses

type AddressLoaderConfig struct {
    // Fetch is a method that provides the data for the loader
    Fetch func(keys []int) ([]*Address, []error)

    // Wait is how long wait before sending a batch
    Wait time.Duration

    // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit
    MaxBatch int
}

AddressLoaderConfig captures the config to create a new AddressLoader

type ComplexityRoot Uses

type ComplexityRoot struct {
    Address struct {
        Country func(childComplexity int) int
        ID      func(childComplexity int) int
        Street  func(childComplexity int) int
    }

    Customer struct {
        Address func(childComplexity int) int
        ID      func(childComplexity int) int
        Name    func(childComplexity int) int
        Orders  func(childComplexity int) int
    }

    Item struct {
        Name func(childComplexity int) int
    }

    Order struct {
        Amount func(childComplexity int) int
        Date   func(childComplexity int) int
        ID     func(childComplexity int) int
        Items  func(childComplexity int) int
    }

    Query struct {
        Customers func(childComplexity int) int
        Torture1d func(childComplexity int, customerIds []int) int
        Torture2d func(childComplexity int, customerIds [][]int) int
    }
}

type Config Uses

type Config struct {
    Resolvers  ResolverRoot
    Directives DirectiveRoot
    Complexity ComplexityRoot
}

type Customer Uses

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

type CustomerResolver Uses

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

type DirectiveRoot Uses

type DirectiveRoot struct {
}

type Item Uses

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

type ItemSliceLoader Uses

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

ItemSliceLoader batches and caches requests

func NewItemSliceLoader Uses

func NewItemSliceLoader(config ItemSliceLoaderConfig) *ItemSliceLoader

NewItemSliceLoader creates a new ItemSliceLoader given a fetch, wait, and maxBatch

func (*ItemSliceLoader) Clear Uses

func (l *ItemSliceLoader) Clear(key int)

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

func (*ItemSliceLoader) Load Uses

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

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

func (*ItemSliceLoader) LoadAll Uses

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) LoadAllThunk Uses

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

LoadAllThunk returns a function that when called will block waiting for a Items. 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) LoadThunk Uses

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 Uses

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 ItemSliceLoaderConfig Uses

type ItemSliceLoaderConfig struct {
    // Fetch is a method that provides the data for the loader
    Fetch func(keys []int) ([][]*Item, []error)

    // Wait is how long wait before sending a batch
    Wait time.Duration

    // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit
    MaxBatch int
}

ItemSliceLoaderConfig captures the config to create a new ItemSliceLoader

type Order Uses

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

type OrderResolver Uses

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

type OrderSliceLoader Uses

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

OrderSliceLoader batches and caches requests

func NewOrderSliceLoader Uses

func NewOrderSliceLoader(config OrderSliceLoaderConfig) *OrderSliceLoader

NewOrderSliceLoader creates a new OrderSliceLoader given a fetch, wait, and maxBatch

func (*OrderSliceLoader) Clear Uses

func (l *OrderSliceLoader) Clear(key int)

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

func (*OrderSliceLoader) Load Uses

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

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

func (*OrderSliceLoader) LoadAll Uses

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) LoadAllThunk Uses

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

LoadAllThunk returns a function that when called will block waiting for a Orders. 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) LoadThunk Uses

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 Uses

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 OrderSliceLoaderConfig Uses

type OrderSliceLoaderConfig struct {
    // Fetch is a method that provides the data for the loader
    Fetch func(keys []int) ([][]*Order, []error)

    // Wait is how long wait before sending a batch
    Wait time.Duration

    // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit
    MaxBatch int
}

OrderSliceLoaderConfig captures the config to create a new OrderSliceLoader

type QueryResolver Uses

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

type Resolver Uses

type Resolver struct{}

func (*Resolver) Customer Uses

func (r *Resolver) Customer() CustomerResolver

func (*Resolver) Order Uses

func (r *Resolver) Order() OrderResolver

func (*Resolver) Query Uses

func (r *Resolver) Query() QueryResolver

type ResolverRoot Uses

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

Directories

PathSynopsis
server

Package dataloader imports 15 packages (graph) and is imported by 2 packages. Updated 2020-08-05. Refresh now. Tools for package owners.