Help us shape the future of Go! Take the 2026 Go Developer Survey

schema

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package schema provides serialization utilities for storing GraphQL schema metadata in database tables. It has zero runtime dependencies — it can be compiled and tested without importing engine, database, or provider packages.

Functions:

  • MarshalDirectives / UnmarshalDirectives: ast.DirectiveList ↔ JSON
  • MarshalType / UnmarshalType: *ast.Type ↔ string
  • ClassifyType / ClassifyField: directive-based HugrType classification

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassifyField

func ClassifyField(field *ast.FieldDefinition, parentDef *ast.Definition, typeLookup func(string) *ast.Definition) base.HugrTypeField

ClassifyField determines the HugrTypeField classification for a field definition based on its directives, naming patterns, and parent type.

The parentDef parameter provides context about where the field is defined. typeLookup resolves type names to definitions for field-type checks (e.g., checking if the field's type has @module_root). Pass nil to skip type-dependent classification.

func ClassifyType

func ClassifyType(def *ast.Definition) base.HugrType

ClassifyType determines the HugrType classification for a type definition based on its directives and name. Returns empty string for unclassified types.

func MarshalArgumentDefinitions

func MarshalArgumentDefinitions(args ast.ArgumentDefinitionList) ([]byte, error)

MarshalArgumentDefinitions serializes an ast.ArgumentDefinitionList to JSON. Used for storing directive argument schemas in _schema_directives.

func MarshalDirectives

func MarshalDirectives(dirs ast.DirectiveList) ([]byte, error)

MarshalDirectives serializes an ast.DirectiveList to a stable, deterministic JSON format. The output is a JSON array of objects:

[{"name": "table", "args": {"name": "users"}}, {"name": "pk"}]

Directives without arguments omit the "args" key. The same input always produces byte-identical output (deterministic).

func MarshalType

func MarshalType(t *ast.Type) string

MarshalType serializes an *ast.Type to its canonical GraphQL string representation (e.g., "[String!]!", "Int", "Boolean!").

func MarshalValue

func MarshalValue(v *ast.Value) any

MarshalValue serializes an *ast.Value to a JSON-compatible Go value. Exported wrapper for the internal marshalValue function.

func UnmarshalArgumentDefinitions

func UnmarshalArgumentDefinitions(data []byte) (ast.ArgumentDefinitionList, error)

UnmarshalArgumentDefinitions deserializes JSON back into an ast.ArgumentDefinitionList.

func UnmarshalDirectives

func UnmarshalDirectives(data []byte) (ast.DirectiveList, error)

UnmarshalDirectives deserializes JSON (produced by MarshalDirectives) back into an ast.DirectiveList with full structural fidelity.

func UnmarshalType

func UnmarshalType(s string) (*ast.Type, error)

UnmarshalType parses a GraphQL type string back into an *ast.Type. Returns an error for malformed input.

func UnmarshalValue

func UnmarshalValue(data json.RawMessage) (*ast.Value, error)

UnmarshalValue deserializes a JSON value back into an *ast.Value. Exported wrapper for the internal unmarshalValue function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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