Documentation
¶
Overview ¶
Package graphql is om's GraphQL protocol: trusted documents, the named operations of executable GraphQL documents validated against the API's schema, served as one tool per named query or mutation. Each operation sends its fixed document as a GraphQL over HTTP request and turns the response into a structured result of the response's data and errors.
Only this package knows GraphQL, and only compiling parses it: a stored operation carries its document as text and its schemas as JSON Schema, so serving needs no GraphQL parser.
Index ¶
Constants ¶
const Format = 1
Format is the version of the GraphQL model this package writes and serves. A model stores it under the key "graphql". Raising it strands stored GraphQL models only.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode(data json.RawMessage) ([]core.Operation, error)
Decode reads the operations of a model whose format is Format. It refuses an operation it could not send as stored: one whose document is not a query or a mutation, including one with no document.
func Draft ¶
Draft compiles source: one candidate per named query or mutation, whose tool is named after the operation and whose schemas are its variables' and its result's. It fails as a whole when the endpoint is not an API server om sends to, when the schema does not load, or when an operations file does not parse: those are the author's mistakes, and no tool list is right until they are fixed. An operation that parses but cannot be a tool is omitted with its reason, as operations decides; core.Finish then omits one whose name is longer than an MCP tool name allows or is already taken.
The draft's title is the endpoint's host, and its description the schema's. Its version is empty: a schema declares none, and every host that needs one substitutes its own. Its server is the endpoint, so it has no inputs of its own.
func Endpoint ¶
Endpoint is raw as the server of a model: an API server om sends to, with a lowercase host. It has no server variables, so it is a plain URL a host may replace.
func Introspect ¶
func Introspect(ctx context.Context, upstream core.Upstream, security core.Security) ([]byte, error)
Introspect reads the schema the API at upstream serves, as the JSON of an introspection result that Draft reads. It is the one place this package drives an exchange, and it does so through core's Upstream, so the credentials and the egress a host imposes apply as they do to every tool call. It reads within a document's size limit, not a tool result's: GitHub's and Linear's SDL are each about 1.6 MB, past the 1 MiB a tool's result may hold.
It asks twice, and never guesses. Servers that predate an edition reject the introspection fields it added, so Introspect first asks which fields, and which arguments of those fields, the introspection types have, and then asks for the whole schema with every field that server has: the schema's description, specifiedByURL and isRepeatable (October 2021), isOneOf and deprecated arguments and input fields (September 2025), and deprecated directives, which graphql-js 17 lists only when asked, as its experimental directive deprecation. Both requests are Operations sent like any tool's, and their responses are read as a tool's are: a request error or null data fails Introspect with the API's errors. https://spec.graphql.org/September2025/#sec-Schema-Introspection
Types ¶
type Kind ¶
type Kind string
Kind is an operation's type. A subscription never compiles: it answers with a stream, not one response.
type Operation ¶
type Operation struct {
core.Tool
// Document is the operation and every fragment it spreads, printed by om without descriptions, which the
// specification lets a client remove and which an API on an older edition would reject. It is the only text om
// ever sends as a query for this tool: an agent chooses arguments, never the document. It also states the
// operation's Kind, so the model stores no second copy that could contradict it.
//
// The model stores no persisted document id. An id this text's hash would give can be computed from it at any
// time, and an id an API accepts is one that API assigned to the text its own tooling registered.
Document string `json:"document"`
Security core.Security `json:"security,omitempty"`
}
Operation is one named operation of a trusted document: the tool it is listed as and the document om sends for it.
Name is the operation's name, which GraphQL's Name grammar keeps within MCP's tool name characters; it is sent as operationName. InputSchema describes the operation's variables, so the validated arguments are sent verbatim as variables. OutputSchema describes the structured result: the response's data, exactly as the selection set shapes it, and its errors.
func (Operation) Annotations ¶
func (o Operation) Annotations() *mcp.ToolAnnotations
Annotations mark a query read-only, which the GraphQL specification makes it: "a read-only fetch". A mutation gets no hints, so clients treat it as possibly destructive and not idempotent. https://spec.graphql.org/September2025/#sec-Language.Operations
func (Operation) Kind ¶
Kind is the operation type the document begins with, as the grammar begins every operation om stores: om prints it without the description that could come first. Any white space may surround it, as GraphQL ignores it. https://spec.graphql.org/September2025/#OperationDefinition
func (Operation) Request ¶
Request is a POST of the operation's document with the arguments as its variables. It never sends onError: the output schema is right only under the specification's default error propagation. https://graphql.github.io/graphql-over-http/draft/#sec-POST
func (Operation) Result ¶
Result turns the response into what the agent receives.
- A response with data that is not null succeeds, partial or not. The structured result is {"data", "errors", "extensions"}: data is checked by core against the selection set's schema, which still holds for partial data because GraphQL nulls the nearest nullable parent of a field that failed. errors, when present, say which paths are missing and why. extensions, when present, carry what the API reports beside the data, such as the query cost Shopify and Saleor send, which an agent can use to pace its calls.
- Any other response with GraphQL errors is an error result listing them: a request error, or an execution that failed at a non-null root field.
- Anything else is an error result naming the HTTP status and body, as an OpenAPI operation's failure does: "HTTP 502: Bad gateway".
Partial data is a success, never an error result. An error result reaches a typed client as a thrown error and reaches some hosts' models without its structured content, and it invites a retry, which repeats the side effects of a mutation that partly succeeded.
type Source ¶
type Source struct {
Endpoint string
Schema []byte
Operations map[string][]byte
Security core.Security
Needs []core.Need
}
Source is a GraphQL API and the trusted documents that choose its tools, after om.GraphQL's credential became the security every operation sends and the inputs that security reads.