graphql

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package graphql implements Githome's GraphQL API v4. The schema under schema/ is the source of truth; gqlgen generates the executable schema into generated/ and the resolver stubs into this package, which are then filled in by hand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mount

func Mount(root *mizu.Router, d Deps)

Mount registers the GraphQL endpoint at both the GHES-style /api/graphql and the github.com-style /graphql, sharing one handler. The routes are scoped to the two methods the handler serves, GET and POST, rather than registered for every method. That is not only tighter (a PUT to the endpoint is a clean 405 instead of reaching the gql transport), it is also what keeps /api/graphql from colliding with the web front's greedy GET /{owner}/{repo} route: a method-less pattern matches more methods but a more general path is also in play, which the Go 1.22 mux cannot order and so rejects at registration. Pinning the method makes GET /api/graphql win cleanly on path specificity.

func NewHandler

func NewHandler(d Deps) http.Handler

NewHandler builds the GraphQL HTTP handler: the gqlgen executable schema over the root resolver, the POST and GET transports gh and octokit use, a parsed query cache, the auth middleware that mirrors the REST surface, the per-request dataloader middleware, and complexity + depth guards.

Types

type Deps

type Deps struct {
	Auth       *auth.Service
	Repos      *domain.RepoService
	Issues     *domain.IssueService
	Pulls      *domain.PRService
	Reviews    *domain.ReviewService
	Checks     *domain.ChecksService
	Batch      *domain.Batcher
	URLs       *presenter.URLBuilder
	NodeFormat nodeid.Format
}

Deps are the dependencies the GraphQL surface needs to mount: the auth service that resolves the request actor, the domain services resolvers fetch through, the presenter that renders the wire shapes, the node-ID format, and the Batcher that backs the per-request dataloaders.

type Loaders added in v0.1.1

type Loaders struct {
	// Users loads a gqlmodel.Actor by user primary key.
	Users *dataloader.Loader[int64, *gqlmodel.Actor]
	// LabelsByIssue loads the label slice for an issue by its primary key.
	LabelsByIssue *dataloader.Loader[int64, []*gqlmodel.Label]
	// AssigneesByIssue loads the assignee slice for an issue by its primary key.
	AssigneesByIssue *dataloader.Loader[int64, []*gqlmodel.Actor]
}

Loaders holds the per-request batch loaders. One instance is created per HTTP request by loadersMiddleware and stored on the request context.

type Resolver

type Resolver struct {
	Repos      *domain.RepoService
	Issues     *domain.IssueService
	Pulls      *domain.PRService
	Reviews    *domain.ReviewService
	Checks     *domain.ChecksService
	URLs       *presenter.URLBuilder
	NodeFormat nodeid.Format
}

Resolver is the GraphQL root resolver. It holds the domain services the resolvers fetch through and the presenter that renders domain values into the gqlmodel wire shapes. Resolvers never touch the store or git directly, the same rule the REST handlers follow.

func (*Resolver) Commit

func (r *Resolver) Commit() generated.CommitResolver

Commit returns generated.CommitResolver implementation.

func (*Resolver) Issue

func (r *Resolver) Issue() generated.IssueResolver

Issue returns generated.IssueResolver implementation.

func (*Resolver) Mutation

func (r *Resolver) Mutation() generated.MutationResolver

Mutation returns generated.MutationResolver implementation.

func (*Resolver) PullRequest

func (r *Resolver) PullRequest() generated.PullRequestResolver

PullRequest returns generated.PullRequestResolver implementation.

func (*Resolver) PullRequestReviewThread

func (r *Resolver) PullRequestReviewThread() generated.PullRequestReviewThreadResolver

PullRequestReviewThread returns generated.PullRequestReviewThreadResolver implementation.

func (*Resolver) Query

func (r *Resolver) Query() generated.QueryResolver

Query returns generated.QueryResolver implementation.

func (*Resolver) Repository

func (r *Resolver) Repository() generated.RepositoryResolver

Repository returns generated.RepositoryResolver implementation.

Directories

Path Synopsis
Package dataloader provides a generic per-request batch loader.
Package dataloader provides a generic per-request batch loader.

Jump to

Keyboard shortcuts

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