Documentation ¶
Index ¶
- func NewExecutableSchema(cfg Config) graphql.ExecutableSchema
- func WithCompanyDataloaderMiddleware(companyClient *client.CompanyClient, next http.Handler) http.Handler
- type Address
- type Company
- type CompanyLoader
- func (l *CompanyLoader) Clear(key int64)
- func (l *CompanyLoader) Load(key int64) (*Company, error)
- func (l *CompanyLoader) LoadAll(keys []int64) ([]*Company, []error)
- func (l *CompanyLoader) LoadAllThunk(keys []int64) func() ([]*Company, []error)
- func (l *CompanyLoader) LoadThunk(key int64) func() (*Company, error)
- func (l *CompanyLoader) Prime(key int64, value *Company) bool
- type CompanyLoaderConfig
- type ComplexityRoot
- type Config
- type DirectiveRoot
- type Item
- type MutationResolver
- type NewCompany
- type NewCompanyAddress
- type NewOrder
- type Order
- type OrderResolver
- type QueryResolver
- type Resolver
- type ResolverRoot
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.
func WithCompanyDataloaderMiddleware ¶
func WithCompanyDataloaderMiddleware(companyClient *client.CompanyClient, next http.Handler) http.Handler
WithCompanyDataloaderMiddleware populates the Data Loader middleware for loading company data.
Types ¶
type CompanyLoader ¶
type CompanyLoader struct {
// contains filtered or unexported fields
}
CompanyLoader batches and caches requests
func NewCompanyLoader ¶
func NewCompanyLoader(config CompanyLoaderConfig) *CompanyLoader
NewCompanyLoader creates a new CompanyLoader given a fetch, wait, and maxBatch
func (*CompanyLoader) Clear ¶
func (l *CompanyLoader) Clear(key int64)
Clear the value at key from the cache, if it exists
func (*CompanyLoader) Load ¶
func (l *CompanyLoader) Load(key int64) (*Company, error)
Load a company by key, batching and caching will be applied automatically
func (*CompanyLoader) LoadAll ¶
func (l *CompanyLoader) LoadAll(keys []int64) ([]*Company, []error)
LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured
func (*CompanyLoader) LoadAllThunk ¶
func (l *CompanyLoader) LoadAllThunk(keys []int64) func() ([]*Company, []error)
LoadAllThunk returns a function that when called will block waiting for a companys. 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 (*CompanyLoader) LoadThunk ¶
func (l *CompanyLoader) LoadThunk(key int64) func() (*Company, error)
LoadThunk returns a function that when called will block waiting for a company. 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 (*CompanyLoader) Prime ¶
func (l *CompanyLoader) Prime(key int64, value *Company) 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 CompanyLoaderConfig ¶
type CompanyLoaderConfig struct { // Fetch is a method that provides the data for the loader Fetch func(keys []int64) ([]*Company, []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 }
CompanyLoaderConfig captures the config to create a new CompanyLoader
type ComplexityRoot ¶
type ComplexityRoot struct { Address struct { Address1 func(childComplexity int) int Address2 func(childComplexity int) int Address3 func(childComplexity int) int Address4 func(childComplexity int) int Country func(childComplexity int) int Postcode func(childComplexity int) int } Company struct { Address func(childComplexity int) int ID func(childComplexity int) int Name func(childComplexity int) int VatNumber func(childComplexity int) int } Item struct { Desc func(childComplexity int) int ID func(childComplexity int) int Price func(childComplexity int) int } Mutation struct { CreateCompany func(childComplexity int, company NewCompany) int CreateOrder func(childComplexity int, companyID string, order NewOrder) int } Order struct { Company func(childComplexity int) int ID func(childComplexity int) int Items func(childComplexity int) int } Query struct { Companies func(childComplexity int, ids []string) int Company func(childComplexity int, id string) int Orders func(childComplexity int, companyID string, ids []string) int } }
type Config ¶
type Config struct { Resolvers ResolverRoot Directives DirectiveRoot Complexity ComplexityRoot }
type DirectiveRoot ¶
type DirectiveRoot struct { }
type MutationResolver ¶
type NewCompany ¶
type NewCompany struct { Name string `json:"name"` VatNumber string `json:"vatNumber"` Address NewCompanyAddress `json:"address"` }
type NewCompanyAddress ¶
type OrderResolver ¶
type QueryResolver ¶
type Resolver ¶
type Resolver struct { //TODO: The Resolver here accepts real clients, but this makes it hard to test. //TODO: It would be better to replace them with interfaces so that they can be mocked out. OrderClient order.OrdersClient CompanyClient *client.CompanyClient }
A Resolver resolves GraphQL requests: both Mutations and Queries.
func NewResolver ¶
func NewResolver(oc order.OrdersClient, cc *client.CompanyClient) *Resolver
NewResolver creates the new GraphQL resolver, with the relevant REST and gRPC clients which provide access to data. These could, in fact, access data directly.
func (*Resolver) Mutation ¶
func (r *Resolver) Mutation() MutationResolver
Mutation returns the MutationResolver which handles any mutation requests.
func (*Resolver) Order ¶
func (r *Resolver) Order() OrderResolver
Order returns the Order resolver. This isn't a query that clients can use, but is actually a way for any Order types retned by a query to lookup additional data, potentially from other services. The orderResolver here uses DataLoader middleware to batch up individual requests together into less backend operations, reducing latency.
func (*Resolver) Query ¶
func (r *Resolver) Query() QueryResolver
Query returns resolvers for the GraphQL queries.
type ResolverRoot ¶
type ResolverRoot interface { Mutation() MutationResolver Order() OrderResolver Query() QueryResolver }