graphapi

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package graphapi does graph stuff

Index

Constants

View Source
const (
	ActionGet    = "get"
	ActionUpdate = "update"
	ActionDelete = "delete"
	ActionCreate = "create"
)

Variables

This section is empty.

Functions

func NewExecutableSchema

func NewExecutableSchema(cfg Config) graphql.ExecutableSchema

NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.

func WithTransactions

func WithTransactions(h *handler.Server, c *ent.Client)

WithTransactions adds the transactioner to the ent db client

Types

type ComplexityRoot

type ComplexityRoot struct {
	Mutation struct {
		CreateTodo func(childComplexity int, input generated.CreateTodoInput) int
		DeleteTodo func(childComplexity int, id string) int
		UpdateTodo func(childComplexity int, id string, input generated.UpdateTodoInput) int
	}

	PageInfo struct {
		EndCursor       func(childComplexity int) int
		HasNextPage     func(childComplexity int) int
		HasPreviousPage func(childComplexity int) int
		StartCursor     func(childComplexity int) int
	}

	Query struct {
		Node  func(childComplexity int, id string) int
		Nodes func(childComplexity int, ids []string) int
		Todo  func(childComplexity int, id string) int
	}

	Todo struct {
		Description func(childComplexity int) int
		ID          func(childComplexity int) int
		Name        func(childComplexity int) int
	}

	TodoCreatePayload struct {
		Todo func(childComplexity int) int
	}

	TodoDeletePayload struct {
		DeletedID func(childComplexity int) int
	}

	TodoUpdatePayload struct {
		Todo func(childComplexity int) int
	}
}

type Config

type Config struct {
	Schema     *ast.Schema
	Resolvers  ResolverRoot
	Directives DirectiveRoot
	Complexity ComplexityRoot
}

type DirectiveRoot

type DirectiveRoot struct {
}

type Handler

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

Handler is an http handler wrapping a Resolver

func (*Handler) Handler

func (h *Handler) Handler() http.HandlerFunc

Handler returns the http.HandlerFunc for the GraphAPI

func (*Handler) Routes

func (h *Handler) Routes(e *echo.Group)

Routes for the the server

type MutationResolver

type MutationResolver interface {
	CreateTodo(ctx context.Context, input generated.CreateTodoInput) (*TodoCreatePayload, error)
	UpdateTodo(ctx context.Context, id string, input generated.UpdateTodoInput) (*TodoUpdatePayload, error)
	DeleteTodo(ctx context.Context, id string) (*TodoDeletePayload, error)
}

type QueryResolver

type QueryResolver interface {
	Node(ctx context.Context, id string) (generated.Noder, error)
	Nodes(ctx context.Context, ids []string) ([]generated.Noder, error)
	Todo(ctx context.Context, id string) (*generated.Todo, error)
}

type Resolver

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

Resolver provides a graph response resolver

func NewResolver

func NewResolver(client *ent.Client) *Resolver

NewResolver returns a resolver configured with the given ent client

func (*Resolver) Handler

func (r *Resolver) Handler(withPlayground bool) *Handler

Handler returns an http handler for a graph resolver

func (*Resolver) Mutation

func (r *Resolver) Mutation() MutationResolver

Mutation returns MutationResolver implementation.

func (*Resolver) Query

func (r *Resolver) Query() QueryResolver

Query returns QueryResolver implementation.

func (Resolver) WithLogger

func (r Resolver) WithLogger(l *zap.SugaredLogger) *Resolver

type ResolverRoot

type ResolverRoot interface {
	Mutation() MutationResolver
	Query() QueryResolver
}

type TodoCreatePayload

type TodoCreatePayload struct {
	// Created todo
	Todo *generated.Todo `json:"todo"`
}

Return response for createTodo mutation

type TodoDeletePayload

type TodoDeletePayload struct {
	// Deleted todo ID
	DeletedID string `json:"deletedID"`
}

Return response for deleteTodo mutation

type TodoUpdatePayload

type TodoUpdatePayload struct {
	// Updated todo
	Todo *generated.Todo `json:"todo"`
}

Return response for updateTodo mutation

Jump to

Keyboard shortcuts

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