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 ¶
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).
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).
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 ¶
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 ¶
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 ¶
NewHandlerFromEnv builds the handler over rs with the limits from MAKTABA_GRAPHQL_MAX_DEPTH and MAKTABA_GRAPHQL_MAX_COMPLEXITY (unset or invalid → the defaults).
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 ¶
ImplementsGraphQLType binds ID to the built-in ID scalar.
func (ID) MarshalJSON ¶
MarshalJSON writes the id as a JSON string.
func (*ID) UnmarshalGraphQL ¶
UnmarshalGraphQL takes an ID argument (a string or an integer).
func (*ID) UnmarshalJSON ¶
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 ¶
ImplementsGraphQLType binds JSON to the JSON scalar.
func (JSON) MarshalJSON ¶
MarshalJSON writes the value into the GraphQL response.
func (*JSON) UnmarshalGraphQL ¶
UnmarshalGraphQL takes an argument value (a literal or a variable).
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON reads a REST response value.
type PersistedStore ¶
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.