schema

package
v0.0.0-...-d724b4b Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 17 Imported by: 0

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.

func WithCompanyDataloaderMiddleware

func WithCompanyDataloaderMiddleware(companyClient *client.CompanyClient, next http.Handler) http.Handler

WithCompanyDataloaderMiddleware populates the Data Loader middleware for loading company data.

Types

type Address

type Address struct {
	Address1 string `json:"address1"`
	Address2 string `json:"address2"`
	Address3 string `json:"address3"`
	Address4 string `json:"address4"`
	Postcode string `json:"postcode"`
	Country  string `json:"country"`
}

type Company

type Company struct {
	ID        string  `json:"id"`
	Name      string  `json:"name"`
	VatNumber string  `json:"vatNumber"`
	Address   Address `json:"address"`
}

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 Item

type Item struct {
	ID    string `json:"id"`
	Desc  string `json:"desc"`
	Price int    `json:"price"`
}

type MutationResolver

type MutationResolver interface {
	CreateCompany(ctx context.Context, company NewCompany) (*Company, error)
	CreateOrder(ctx context.Context, companyID string, order NewOrder) (*Order, error)
}

type NewCompany

type NewCompany struct {
	Name      string            `json:"name"`
	VatNumber string            `json:"vatNumber"`
	Address   NewCompanyAddress `json:"address"`
}

type NewCompanyAddress

type NewCompanyAddress struct {
	Address1 string `json:"address1"`
	Address2 string `json:"address2"`
	Address3 string `json:"address3"`
	Address4 string `json:"address4"`
	Postcode string `json:"postcode"`
	Country  string `json:"country"`
}

type NewOrder

type NewOrder struct {
	Items []string `json:"items"`
}

type Order

type Order struct {
	ID        string `json:"id"`
	Items     []Item `json:"items"`
	CompanyID int64  `json:"companyId"`
}

type OrderResolver

type OrderResolver interface {
	Company(ctx context.Context, obj *Order) (*Company, error)
}

type QueryResolver

type QueryResolver interface {
	Orders(ctx context.Context, companyID string, ids []string) ([]Order, error)
	Company(ctx context.Context, id string) (*Company, error)
	Companies(ctx context.Context, ids []string) ([]Company, error)
}

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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