graphqlutil

package
v0.0.0-...-04ccfb0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MaxPageSize uint64 = 100

Variables

View Source
var Date = graphql.NewScalar(graphql.ScalarConfig{
	Name: "Date",
	Description: "The `Date` scalar type represents a Date." +
		" The Date is serialized in ISO 8601 format",
	Serialize:  serializeDate,
	ParseValue: unserializeDate,
	ParseLiteral: func(valueAST ast.Value) interface{} {
		switch valueAST := valueAST.(type) {
		case *ast.StringValue:
			return unserializeDate(valueAST.Value)
		}
		return nil
	},
})

Functions

func HTTPDo

func HTTPDo(r *http.Request, params DoParams) (result *graphql.Result, err error)

HTTPDo is the HTTP version of graphql.Do.

func NewConnectionDef

func NewConnectionDef(schema *graphql.Object) *relay.GraphQLConnectionDefinitions

func NewJSONObjectScalar

func NewJSONObjectScalar(name string, description string) *graphql.Scalar

func WithContext

func WithContext(ctx context.Context, gqlContext GraphQLContext) context.Context

Types

type APIErrorExtension

type APIErrorExtension struct{}

func (APIErrorExtension) ExecutionDidStart

func (APIErrorExtension) GetResult

func (a APIErrorExtension) GetResult(ctx context.Context) interface{}

func (APIErrorExtension) HasResult

func (a APIErrorExtension) HasResult() bool

func (APIErrorExtension) Init

func (APIErrorExtension) Name

func (a APIErrorExtension) Name() string

func (APIErrorExtension) ParseDidStart

func (APIErrorExtension) ResolveFieldDidStart

func (APIErrorExtension) ValidationDidStart

type Connection

type Connection struct {
	Edges      []*relay.Edge  `json:"edges"`
	PageInfo   relay.PageInfo `json:"pageInfo"`
	TotalCount interface{}    `json:"totalCount"`
}

func NewConnectionFromArray

func NewConnectionFromArray(data []interface{}, args relay.ConnectionArguments) *Connection

func NewConnectionFromResult

func NewConnectionFromResult(lazyItems []LazyItem, result *PageResult) (*Connection, error)

type Cursor

type Cursor string

type DataLoader

type DataLoader struct {
	MaxBatch int
	// contains filtered or unexported fields
}

func NewDataLoader

func NewDataLoader(loadFn LoadFunc) *DataLoader

func (*DataLoader) Clear

func (l *DataLoader) Clear(key interface{})

func (*DataLoader) ClearAll

func (l *DataLoader) ClearAll()

func (*DataLoader) Load

func (l *DataLoader) Load(key interface{}) *Lazy

func (*DataLoader) LoadMany

func (l *DataLoader) LoadMany(keys []interface{}) *Lazy

func (*DataLoader) Prime

func (l *DataLoader) Prime(key interface{}, value interface{})

type DataLoaderInterface

type DataLoaderInterface interface {
	Load(key interface{}) *Lazy
	LoadMany(keys []interface{}) *Lazy
	Clear(key interface{})
	ClearAll()
	Prime(key interface{}, value interface{})
}

type DoParams

type DoParams struct {
	OperationName string                 `json:"operationName,omitempty"`
	Query         string                 `json:"query"`
	Variables     map[string]interface{} `json:"variables"`
}

DoParams is the simplfied version of graphql.Params.

type GraphQLContext

type GraphQLContext interface {
	Logger() *log.Logger
}

func GQLContext

func GQLContext(ctx context.Context) GraphQLContext

type GraphiQL

type GraphiQL struct {
	Title string
}

func (*GraphiQL) ServeHTTP

func (g *GraphiQL) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Lazy

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

func NewLazy

func NewLazy(init func() (interface{}, error)) *Lazy

func NewLazyError

func NewLazyError(err error) *Lazy

func NewLazyValue

func NewLazyValue(value interface{}) *Lazy

func (*Lazy) Map

func (l *Lazy) Map(mapFn func(interface{}) (interface{}, error)) *Lazy

func (*Lazy) MapTo

func (l *Lazy) MapTo(value interface{}) *Lazy

func (*Lazy) Value

func (l *Lazy) Value() (interface{}, error)

type LazyItem

type LazyItem struct {
	Lazy   *Lazy
	Cursor Cursor
}

type LoadFunc

type LoadFunc func(keys []interface{}) ([]interface{}, error)

LoadFunc must satisfy the following conditions.

1. The length of the result must match that of keys. 2. If a given key resolves to nothing, nil must be returned instead. 3. The order of the result must match that of keys.

So it is the responsibility of LoadFunc to satisfy these conditions. The underlying implementation used by LoadFunc may not satisfy the conditions.

type PageArgs

type PageArgs struct {
	Before Cursor
	After  Cursor
	First  *uint64
	Last   *uint64
}

func NewPageArgs

func NewPageArgs(args relay.ConnectionArguments) PageArgs

type PageResult

type PageResult struct {
	HasPreviousPage bool
	HasNextPage     bool
	TotalCount      *Lazy
}

func NewPageResult

func NewPageResult(args PageArgs, itemsLen int, totalCount *Lazy) *PageResult

Jump to

Keyboard shortcuts

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