graphql

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NameFromIdentifier

func NameFromIdentifier(identifier string) string

NameFromIdentifier makes a safe GraphQL type name from a field identifier.

Types

type ArgDef

type ArgDef struct {
	Name     string
	Type     TypeRef
	Declared bool
}

ArgDef is a root-field argument. Declared marks arguments whose type came from a variable definition and therefore takes precedence over literals.

type Argument

type Argument struct {
	Name  string
	Value Value
}

Argument is a named field argument.

type Config

type Config struct {
	Title       string
	Description string
	Version     string
}

Config configures GraphQL SDL generation.

type Document

type Document struct {
	Operations []*Operation
	Fragments  []*Fragment
}

Document is a parsed GraphQL document.

func ParseDocument

func ParseDocument(source string) (*Document, error)

ParseDocument parses a GraphQL document without executing it.

type Field

type Field struct {
	Alias           string
	Name            string
	Arguments       []Argument
	SelectionSet    []*Field
	FragmentSpreads []string
	InlineFragments []*InlineFragment
}

Field is a selected GraphQL field.

type FieldDef

type FieldDef struct {
	Name string
	Type TypeRef
}

FieldDef is a field in an SDL object or input type.

type Fragment

type Fragment struct {
	Name          string
	TypeCondition string
	SelectionSet  []*Field
}

Fragment is a named fragment definition.

type Generator

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

Generator builds a GraphQL SDL schema from captured HTTP transactions.

func NewGenerator

func NewGenerator(config Config) *Generator

NewGenerator creates a GraphQL SDL generator.

func (*Generator) AddTransaction

func (g *Generator) AddTransaction(transaction proxy.APITransaction)

AddTransaction adds a captured transaction. Non-GraphQL transactions are ignored by design.

func (*Generator) Generate

func (g *Generator) Generate() (string, error)

Generate produces deterministic GraphQL SDL.

type InlineFragment

type InlineFragment struct {
	TypeCondition string
	SelectionSet  []*Field
}

InlineFragment is an inline fragment selection.

type ObjectField

type ObjectField struct {
	Name  string
	Value Value
}

ObjectField is a field in an object literal value.

type Operation

type Operation struct {
	Kind         string
	Name         string
	Variables    []*VariableDef
	SelectionSet []*Field
}

Operation is a query, mutation, or subscription operation.

type ParsedRequest

type ParsedRequest struct {
	Document  *Document
	Variables map[string]any
}

ParsedRequest is a captured HTTP request identified as GraphQL.

func ParseRequest

func ParseRequest(transaction proxy.APITransaction) (*ParsedRequest, bool)

ParseRequest detects and parses GraphQL carried by one captured HTTP transaction. Non-GraphQL traffic returns ok=false.

type TypeDef

type TypeDef struct {
	Name   string
	Input  bool
	Fields map[string]FieldDef
	Shape  string
}

TypeDef is a named object or input type.

type TypeRef

type TypeRef struct {
	Named   string
	Elem    *TypeRef
	NonNull bool
}

TypeRef is a GraphQL type reference. Elem is set for list types; Named is set for named and scalar types. NonNull applies to this node, not its child.

func ParseTypeReference

func ParseTypeReference(source string) (TypeRef, error)

ParseTypeReference parses a GraphQL type reference such as [User!]!.

func (TypeRef) IsZero

func (t TypeRef) IsZero() bool

func (TypeRef) String

func (t TypeRef) String() string

type Value

type Value struct {
	Kind    ValueKind
	Text    string
	Bool    bool
	List    []Value
	Object  []ObjectField
	VarName string
}

Value is a GraphQL literal or variable reference.

func (Value) ToGoValue

func (v Value) ToGoValue() any

ToGoValue converts a parsed GraphQL literal to a JSON-like Go value. Variable references return nil because their runtime value is not in the query document.

type ValueKind

type ValueKind string

ValueKind identifies the kind of a GraphQL argument or default value.

const (
	ValueInt      ValueKind = "int"
	ValueFloat    ValueKind = "float"
	ValueString   ValueKind = "string"
	ValueBoolean  ValueKind = "boolean"
	ValueNull     ValueKind = "null"
	ValueEnum     ValueKind = "enum"
	ValueList     ValueKind = "list"
	ValueObject   ValueKind = "object"
	ValueVariable ValueKind = "variable"
)

type VariableDef

type VariableDef struct {
	Name       string
	Type       string
	HasDefault bool
}

VariableDef declares a typed operation variable.

Jump to

Keyboard shortcuts

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