graph

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 15 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.

Types

type ComplexityRoot

type ComplexityRoot struct {
	FileAttachment struct {
		CreatedAt func(childComplexity int) int
		Filename  func(childComplexity int) int
		ID        func(childComplexity int) int
		MimeType  func(childComplexity int) int
		Size      func(childComplexity int) int
		Title     func(childComplexity int) int
	}

	LinkAttachment struct {
		CreatedAt   func(childComplexity int) int
		Description func(childComplexity int) int
		ID          func(childComplexity int) int
		Title       func(childComplexity int) int
		URL         func(childComplexity int) int
	}

	Mutation struct {
		AddFileAttachment func(childComplexity int, todoID string, title string, file graphql.Upload) int
		AddLinkAttachment func(childComplexity int, todoID string, title string, url string, description *string) int
		CompleteTodo      func(childComplexity int, id string) int
		CreateTodo        func(childComplexity int, input model.CreateTodoInput) int
		CreateUser        func(childComplexity int, input model.CreateUserInput) int
		DeleteTodo        func(childComplexity int, id string) int
		RemoveAttachment  func(childComplexity int, todoID string, attachmentID string) int
		UpdateTodo        func(childComplexity int, input model.UpdateTodoInput) int
	}

	Query struct {
		CurrentTime func(childComplexity int) int
		Echo        func(childComplexity int, message string) int
		Hello       func(childComplexity int) int
		Node        func(childComplexity int, id string) int
		Search      func(childComplexity int, term string, limit *int32) int
		Todo        func(childComplexity int, id string) int
		Todos       func(childComplexity int, filters *model.TodoFilters, limit *int32, offset *int32) int
		User        func(childComplexity int, id string) int
		Users       func(childComplexity int, limit *int32, offset *int32) int
		Version     func(childComplexity int) int
	}

	Subscription struct {
		Counter    func(childComplexity int) int
		Tick       func(childComplexity int, interval *int32) int
		TodoEvents func(childComplexity int) int
		UserEvents func(childComplexity int) int
	}

	Todo struct {
		AssignedTo  func(childComplexity int) int
		Attachments func(childComplexity int) int
		CreatedAt   func(childComplexity int) int
		CreatedBy   func(childComplexity int) int
		DueDate     func(childComplexity int) int
		ID          func(childComplexity int) int
		Notes       func(childComplexity int) int
		Priority    func(childComplexity int) int
		Status      func(childComplexity int) int
		Tags        func(childComplexity int) int
		Title       func(childComplexity int) int
		UpdatedAt   func(childComplexity int) int
	}

	User struct {
		Avatar         func(childComplexity int) int
		CompletedCount func(childComplexity int) int
		CreatedAt      func(childComplexity int) int
		Email          func(childComplexity int) int
		ID             func(childComplexity int) int
		Name           func(childComplexity int) int
		Role           func(childComplexity int) int
		Todos          func(childComplexity int, status *model.TodoStatus, limit *int32, offset *int32) int
		Website        func(childComplexity int) int
	}
}

type Config

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

type DirectiveRoot

type DirectiveRoot struct {
}

type EntityStore

type EntityStore[T any] struct {
	// contains filtered or unexported fields
}

EntityStore provides generic CRUD operations for entities using generics

func NewEntityStore

func NewEntityStore[T any](typeName string) *EntityStore[T]

NewEntityStore creates a new entity store

func (*EntityStore[T]) Create

func (es *EntityStore[T]) Create(entity T) (string, T)

Create adds a new entity with an auto-generated ID

func (*EntityStore[T]) Delete

func (es *EntityStore[T]) Delete(id string) bool

Delete removes an entity

func (*EntityStore[T]) Get

func (es *EntityStore[T]) Get(id string) (T, bool)

Get retrieves an entity by global ID

func (*EntityStore[T]) GetAll

func (es *EntityStore[T]) GetAll() []T

GetAll returns all entities

func (*EntityStore[T]) Update

func (es *EntityStore[T]) Update(id string, entity T) bool

Update modifies an existing entity

type MutationResolver

type MutationResolver interface {
	CreateUser(ctx context.Context, input model.CreateUserInput) (*model.User, error)
	CreateTodo(ctx context.Context, input model.CreateTodoInput) (*model.Todo, error)
	UpdateTodo(ctx context.Context, input model.UpdateTodoInput) (*model.Todo, error)
	DeleteTodo(ctx context.Context, id string) (bool, error)
	CompleteTodo(ctx context.Context, id string) (*model.Todo, error)
	AddFileAttachment(ctx context.Context, todoID string, title string, file graphql.Upload) (*model.FileAttachment, error)
	AddLinkAttachment(ctx context.Context, todoID string, title string, url string, description *string) (*model.LinkAttachment, error)
	RemoveAttachment(ctx context.Context, todoID string, attachmentID string) (bool, error)
}

type QueryResolver

type QueryResolver interface {
	Node(ctx context.Context, id string) (model.Node, error)
	Hello(ctx context.Context) (string, error)
	Echo(ctx context.Context, message string) (string, error)
	User(ctx context.Context, id string) (*model.User, error)
	Users(ctx context.Context, limit *int32, offset *int32) ([]*model.User, error)
	Todo(ctx context.Context, id string) (*model.Todo, error)
	Todos(ctx context.Context, filters *model.TodoFilters, limit *int32, offset *int32) ([]*model.Todo, error)
	Search(ctx context.Context, term string, limit *int32) ([]model.SearchResult, error)
	CurrentTime(ctx context.Context) (*time.Time, error)
	Version(ctx context.Context) (string, error)
}

type Resolver

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

func NewResolver

func NewResolver() *Resolver

NewResolver creates a new Resolver with an initialized data store

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) Subscription

func (r *Resolver) Subscription() SubscriptionResolver

Subscription returns SubscriptionResolver implementation.

type ResolverRoot

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

type Store

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

Store provides thread-safe in-memory storage for the mock server

func NewStore

func NewStore() *Store

NewStore creates a new Store with pre-seeded data

func (*Store) AddAttachmentToTodo

func (s *Store) AddAttachmentToTodo(todoID, attachmentID string)

AddAttachmentToTodo links an attachment to a todo

func (*Store) BroadcastTodoEvent

func (s *Store) BroadcastTodoEvent(todo *model.Todo)

BroadcastTodoEvent sends a todo to all active subscribers. This should be called after any create, update, or delete operation.

func (*Store) BroadcastUserEvent

func (s *Store) BroadcastUserEvent(user *model.User)

BroadcastUserEvent sends a user to all active subscribers. This should be called after any create or update operation.

func (*Store) CreateFileAttachment

func (s *Store) CreateFileAttachment(title, filename, mimeType string, size int) *model.FileAttachment

CreateFileAttachment adds a new file attachment

func (*Store) CreateLinkAttachment

func (s *Store) CreateLinkAttachment(title, url string, description *string) *model.LinkAttachment

CreateLinkAttachment adds a new link attachment

func (*Store) CreateTodo

func (s *Store) CreateTodo(title string, createdByID string, input *model.CreateTodoInput) *model.Todo

CreateTodo adds a new todo to the store

func (*Store) CreateUser

func (s *Store) CreateUser(name, email string, role model.UserRole, website *string) *model.User

CreateUser adds a new user to the store

func (*Store) DeleteTodo

func (s *Store) DeleteTodo(id string) bool

DeleteTodo removes a todo from the store

func (*Store) GetFileAttachment

func (s *Store) GetFileAttachment(id string) (*model.FileAttachment, error)

GetFileAttachment retrieves a file attachment by global ID

func (*Store) GetLinkAttachment

func (s *Store) GetLinkAttachment(id string) (*model.LinkAttachment, error)

GetLinkAttachment retrieves a link attachment by global ID

func (*Store) GetTodo

func (s *Store) GetTodo(id string) (*model.Todo, error)

GetTodo retrieves a todo by global ID

func (*Store) GetTodos

func (s *Store) GetTodos() []*model.Todo

GetTodos returns all todos

func (*Store) GetUser

func (s *Store) GetUser(id string) (*model.User, error)

GetUser retrieves a user by global ID

func (*Store) GetUsers

func (s *Store) GetUsers() []*model.User

GetUsers returns all users

func (*Store) RemoveAttachmentFromTodo

func (s *Store) RemoveAttachmentFromTodo(todoID, attachmentID string) bool

RemoveAttachmentFromTodo unlinks an attachment from a todo

func (*Store) SubscribeToTodoEvents

func (s *Store) SubscribeToTodoEvents(ch chan *model.Todo) int

SubscribeToTodoEvents registers a channel to receive todo events. Returns a subscriber ID that should be used to unsubscribe.

func (*Store) SubscribeToUserEvents

func (s *Store) SubscribeToUserEvents(ch chan *model.User) int

SubscribeToUserEvents registers a channel to receive user events. Returns a subscriber ID that should be used to unsubscribe.

func (*Store) UnsubscribeFromTodoEvents

func (s *Store) UnsubscribeFromTodoEvents(id int)

UnsubscribeFromTodoEvents removes a todo event subscriber.

func (*Store) UnsubscribeFromUserEvents

func (s *Store) UnsubscribeFromUserEvents(id int)

UnsubscribeFromUserEvents removes a user event subscriber.

func (*Store) UpdateTodo

func (s *Store) UpdateTodo(id string, input *model.UpdateTodoInput) (*model.Todo, error)

UpdateTodo updates an existing todo

type SubscriberManager

type SubscriberManager[T any] struct {
	// contains filtered or unexported fields
}

SubscriberManager manages subscriptions for a specific event type using generics

func NewSubscriberManager

func NewSubscriberManager[T any]() *SubscriberManager[T]

NewSubscriberManager creates a new subscriber manager

func (*SubscriberManager[T]) Broadcast

func (sm *SubscriberManager[T]) Broadcast(event T)

Broadcast sends an event to all active subscribers (non-blocking)

func (*SubscriberManager[T]) Subscribe

func (sm *SubscriberManager[T]) Subscribe(ch chan T) int

Subscribe registers a channel to receive events

func (*SubscriberManager[T]) Unsubscribe

func (sm *SubscriberManager[T]) Unsubscribe(id int)

Unsubscribe removes a subscriber

type SubscriptionResolver

type SubscriptionResolver interface {
	Counter(ctx context.Context) (<-chan int32, error)
	TodoEvents(ctx context.Context) (<-chan *model.Todo, error)
	Tick(ctx context.Context, interval *int32) (<-chan *time.Time, error)
	UserEvents(ctx context.Context) (<-chan *model.User, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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