graphql

package
v0.0.0-...-79b1474 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package graphql is the GraphQL surface of the API (Story 7.17).

The schema is one SDL document (Schema, kept byte-identical to shared/graphql/schema.graphql by TestSharedSchemaInSync) laid over the REST API. Every root field is answered by the REST handler that owns the same operation, called in process through the API router (see bridge.go), so authentication, admin checks, row-level library visibility, rate limits, Idempotency-Key replay and audit writes are the REST ones, not a second copy. Nested video fields (tags, media info, audio tracks, subtitles, chapters, transcript, playback state) are batched per list through the videos package's batch loaders, the same functions the REST video detail uses (loaders.go).

Execution uses graph-gophers/graphql-go (schema first, no codegen); cost.go adds the depth and complexity limits; subscriptions.go serves the Subscription fields over graphql-transport-ws on top of the Story 7.16 event hub.

Index

Constants

View Source
const (
	DefaultMaxDepth      = 12
	DefaultMaxComplexity = 10000
	// DefaultListSize is the assumed length of a list field without a
	// limit / first argument.
	DefaultListSize = 20
)

Defaults for the limits (Handler.MaxDepth / MaxComplexity override).

View Source
const (
	PersistedQueryNotFound    = "PersistedQueryNotFound"
	CodePersistedNotFound     = "PERSISTED_QUERY_NOT_FOUND"
	CodePersistedHashMismatch = "PERSISTED_QUERY_HASH_MISMATCH"
	CodePersistedNotAllowed   = "PERSISTED_QUERY_NOT_ALLOWED"
)

Apollo's error message and code for an unknown hash (clients match on them to retry with the full text).

View Source
const Schema = `` /* 6798-byte string literal not displayed */

Schema is the SDL source for the API. Story 7.17 AC-1 + AC-2 list every domain type and root field this schema must expose.

Variables

View Source
var SubRequestGate atomic.Pointer[func(http.Handler) http.Handler]

reqKey carries the outer GraphQL request on the resolver context. SubRequestGate, when set, wraps the router each field's REST sub-request runs on: the gates the public mux puts in front of the router (the seat gate, story 16.4) hold for a GraphQL field as for the REST route it runs.

Functions

func QueryHash

func QueryHash(query string) string

QueryHash is the lowercase hex sha256 of an operation's text, the id a client sends.

Types

type Bridge

type Bridge struct {
	// Router is the API's root router (the chi mux every REST handler is
	// mounted on).
	Router http.Handler
}

Bridge dispatches REST sub-requests into Router.

type Handler

type Handler struct {
	Resolvers *Resolvers
	// MaxDepth / MaxComplexity bound an operation (cost.go); zero means
	// DefaultMaxDepth / DefaultMaxComplexity.
	MaxDepth      int
	MaxComplexity int
	// Persisted is the persisted-query store (persisted.go); nil holds
	// nothing, so every hash misses. PersistedOnly reports allowlist mode
	// (the graphql.persisted_only setting); nil is off.
	Persisted     *PersistedStore
	PersistedOnly func(context.Context) bool
	// contains filtered or unexported fields
}

Handler is the GraphQL endpoint:

POST /graphql          queries and mutations (GraphQL over HTTP)
GET  /graphql          subscriptions (graphql-transport-ws upgrade)
GET  /graphql/schema   the SDL

Every operation needs an authenticated caller; what the caller may do is then decided by the REST routes the fields run (bridge.go).

func NewHandlerFromEnv

func NewHandlerFromEnv(rs *Resolvers) *Handler

NewHandlerFromEnv builds the handler over rs with the limits from MAKTABA_GRAPHQL_MAX_DEPTH and MAKTABA_GRAPHQL_MAX_COMPLEXITY (unset or invalid → the defaults).

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ID

type ID string

ID is the schema's ID scalar. REST ids are UUID strings or integers (jobs, segments, subtitles); both read into ID and leave as a string.

func (ID) ImplementsGraphQLType

func (ID) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType binds ID to the built-in ID scalar.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON writes the id as a JSON string.

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalGraphQL

func (id *ID) UnmarshalGraphQL(input any) error

UnmarshalGraphQL takes an ID argument (a string or an integer).

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a REST id: a JSON string or number.

type JSON

type JSON struct{ V any }

JSON is the schema's JSON scalar: any JSON value, in and out.

func (JSON) ImplementsGraphQLType

func (JSON) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType binds JSON to the JSON scalar.

func (JSON) MarshalJSON

func (j JSON) MarshalJSON() ([]byte, error)

MarshalJSON writes the value into the GraphQL response.

func (*JSON) UnmarshalGraphQL

func (j *JSON) UnmarshalGraphQL(input any) error

UnmarshalGraphQL takes an argument value (a literal or a variable).

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a REST response value.

type PersistedStore

type PersistedStore struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

PersistedStore holds the persisted operations: the graphql_persisted_queries table (slot 0140) behind a bounded in-memory cache. A nil store (or nil DB) holds nothing.

func NewPersistedStore

func NewPersistedStore(db *sql.DB) *PersistedStore

NewPersistedStore returns the store over db.

func (*PersistedStore) Lookup

func (s *PersistedStore) Lookup(ctx context.Context, hash string) (string, bool, error)

Lookup returns the operation stored under hash.

func (*PersistedStore) Register

func (s *PersistedStore) Register(ctx context.Context, query, userID string) error

Register stores query under its own hash (idempotent).

type Resolvers

type Resolvers struct {
	Bridge *Bridge
	DB     *sql.DB
	Hub    *ws.Hub
	// contains filtered or unexported fields
}

Resolvers holds what the resolvers need: the REST bridge, the app database (for the batch loaders of nested video fields only) and the event hub the subscriptions read.

func NewResolvers

func NewResolvers(router http.Handler, db *sql.DB, hub *ws.Hub) *Resolvers

NewResolvers builds the resolvers over the API router (REST handlers), the app database and the event hub.

Jump to

Keyboard shortcuts

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