moonbitstack/moongql/schema does not have a README file

    FieldDirectiveHook

    type FieldDirectiveHook = (Json, Map[String, Json]) -> Json

    The run-time hook a user directive may carry: given the resolved field value and the directive's coerced arguments, return the transformed value. This is how a custom executable directive (@upper, @default(value:), ...) alters a field after its resolver has run.

    AppliedDirective

    pub(all) struct AppliedDirective {
    name : String
    args : Array[(String, Json)]
    }

    A directive applied to a schema element: its name and its constant arguments as ordered (name, value) pairs. Build one with AppliedDirective::new.

    AppliedDirective::new

    fn AppliedDirective::new(name : String, args? : Array[(String, Json)]) -> AppliedDirective

    An applied directive with no arguments, or with the given constant arguments.

    DirectiveDef

    pub(all) struct DirectiveDef {
    name : String
    locations : Array[String]
    args : Array[(String, GqlType)]
    is_repeatable : Bool
    on_field : (Json, Map[String, Json]) -> Json?
    }

    A directive definition: its name, the locations it may appear at (the __DirectiveLocation enum values, e.g. "FIELD", "FIELD_DEFINITION"), its declared args, whether it is_repeatable, and an optional executable on_field hook. A definition with locations that include executable ones and an on_field hook is applied during execution; one with only type-system locations is a pure schema directive (SDL + introspection only).

    EnumType

    pub(all) struct EnumType {
    name : String
    values : Array[String]
    deprecations : Map[String, String]
    description : String?
    value_descriptions : Map[String, String]
    }

    A GraphQL enum type: a name, an ordered list of value names, and each value's @deprecated reason keyed by value name (mirroring Field.arg_defaults).

    Field

    pub(all) struct Field {
    name : String
    args : Array[(String, GqlType)]
    typ : GqlType
    arg_defaults : Map[String, Json]
    deprecation_reason : String?
    description : String?
    }

    A field on an object type: a name, an ordered list of arguments (each a (name, type) pair), and the field's return type. A field with no arguments prints as name: Type; with arguments it prints as name(a: A, b: B): Type.

    GqlType

    pub(all) enum GqlType {
    Scalar(String)
    Named(String)
    NonNull(GqlType)
    ListOf(GqlType)
    } derive(Eq)

    A GraphQL type reference: a scalar (String, Int, Boolean, Float, ID), a named object type, or a non-null / list wrapper around another type.

    GqlType::equal

    fn GqlType::equal(GqlType, GqlType) -> Bool

    GqlType::named_base

    fn GqlType::named_base(self : GqlType) -> String

    The base named type a possibly-wrapped type refers to (unwrapping !/[]).

    GqlType::not_equal

    fn GqlType::not_equal(x : GqlType, y : GqlType) -> Bool

    ObjectType

    pub(all) struct ObjectType {
    name : String
    fields : Array[Field]
    kind : TypeKind
    interfaces : Array[String]
    description : String?
    }

    A GraphQL composite type with an ordered set of fields. The same shape backs output objects, input objects, and interfaces; kind selects the SDL keyword and interfaces lists the interfaces an object implements.

    ObjectType::field

    fn ObjectType::field(self : ObjectType, name : String, typ : GqlType, deprecation_reason? : String, description? : String) -> Unit

    Add a field with no arguments to this type.

    ObjectType::field_args

    fn ObjectType::field_args(self : ObjectType, name : String, args : Array[(String, GqlType)], typ : GqlType, defaults? : Array[(String, Json)], deprecation_reason? : String, description? : String) -> Unit

    Add a field carrying arguments to this type. Each argument is a (name, type) pair and renders as name(a: A, b: B): RetType. defaults supplies default values for arguments a query may omit (GraphQL field-argument defaults): an absent argument takes its default, an explicitly-null one does not.

    ObjectType::field_by_name

    fn ObjectType::field_by_name(self : ObjectType, name : String) -> Field?

    Look up a field on this type by its name.

    ObjectType::implements

    fn ObjectType::implements(self : ObjectType, name : String) -> Unit

    Declare that this object type implements a named interface. Implemented interfaces render as type Name implements A & B { ... }.

    ScalarType

    pub(all) struct ScalarType {
    name : String
    serialize : (Json) -> Json
    parse_value : (Json) -> Json
    spec_url : String?
    description : String?
    }

    A custom scalar type and its two coercion hooks: serialize maps a resolved value to its output JSON, and parse_value maps an input JSON value (an argument or a variable) to the value a resolver sees. Both default to identity when a scalar only renames an existing representation.

    Schema

    pub struct Schema {
    types : Array[ObjectType]
    enums : Array[EnumType]
    unions : Array[UnionType]
    scalars : Array[ScalarType]
    query : String
    mutation : String?
    subscription : String?
    field_directives : Map[String, Array[AppliedDirective]]
    type_directives : Map[String, Array[AppliedDirective]]
    schema_directives : Array[AppliedDirective]
    directive_defs : Array[DirectiveDef]
    }

    A code-first GraphQL schema: composite types (objects, inputs, interfaces), enum types, plus the names of the root operation types. query is required; mutation and subscription are optional (a schema without them cannot run operations of that kind).

    Schema::apply_field_directive

    fn Schema::apply_field_directive(self : Schema, type_name : String, field_name : String, directive : AppliedDirective) -> Unit

    Record an applied directive on the field type_name.field_name.

    Schema::apply_schema_directive

    fn Schema::apply_schema_directive(self : Schema, directive : AppliedDirective) -> Unit

    Record an applied directive on the schema itself (e.g. federation's @link).

    Schema::apply_type_directive

    fn Schema::apply_type_directive(self : Schema, type_name : String, directive : AppliedDirective) -> Unit

    Record an applied directive on the type type_name.

    Schema::directive

    fn Schema::directive(self : Schema, name : String, locations~ : Array[String], args? : Array[(String, GqlType)], is_repeatable? : Bool, on_field? : (Json, Map[String, Json]) -> Json) -> Unit

    Register a directive definition on the schema. locations lists where it may be used ("FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT", "OBJECT", "FIELD_DEFINITION", ...); args declares its arguments; on_field — when given and the directive targets fields — transforms the resolved value of any field the directive is applied to. The directive then appears in introspection (__schema { directives }) and is accepted by the validator.

    Schema::directive_def_by_name

    fn Schema::directive_def_by_name(self : Schema, name : String) -> DirectiveDef?

    The registered directive definition named name, if any.

    Schema::enum_

    fn Schema::enum_(self : Schema, name : String, values : Array[String], deprecated? : Array[(String, String)], description? : String, descriptions? : Array[(String, String)]) -> Unit

    Declare an enum type with an ordered set of value names. Renders as enum Name { A B } with one value per line. deprecated marks individual values @deprecated, each a (value, reason) pair (as field_args takes argument defaults), surfacing in introspection's isDeprecated.

    Schema::enum_by_name

    fn Schema::enum_by_name(self : Schema, name : String) -> EnumType?

    Look up a declared enum type by name.

    Schema::field_applied_directives

    fn Schema::field_applied_directives(self : Schema, type_name : String, field_name : String) -> Array[AppliedDirective]

    The directives applied to the field type_name.field_name.

    Schema::field_has_directive

    fn Schema::field_has_directive(self : Schema, type_name : String, field_name : String, name : String) -> Bool

    Whether the field type_name.field_name carries the directive name.

    Schema::input

    fn Schema::input(self : Schema, name : String, description? : String) -> ObjectType

    Declare an input object type and return it so fields can be added. Renders as input Name { ... }.

    Schema::interface

    fn Schema::interface(self : Schema, name : String, description? : String) -> ObjectType

    Declare an interface type and return it so fields can be added. Renders as interface Name { ... }; objects declare conformance via implements.

    Schema::new

    fn Schema::new(query? : String) -> Schema

    Create an empty schema whose root query type is query (default Query), with no mutation or subscription root until set_mutation / set_subscription name them.

    Schema::object

    fn Schema::object(self : Schema, name : String, description? : String) -> ObjectType

    Declare an output object type and return it so fields can be added. The type is registered by reference, so later .field(...) calls are seen.

    Schema::of_sdl

    Build a schema from a type-system document (SDL), the inverse of to_sdl. A document that is not a well-formed type-system definition raises GqlSyntaxError carrying the line and column of the token that stopped it.

    The hooks SDL cannot carry come back as the identity: a custom scalar's serialize / parse_value, and a directive definition's on_field.

    let s = Schema::of_sdl(
    (
    #|schema { query: Query }
    #|
    #|"The root of everything."
    #|type Query {
    #| "Greets you."
    #| hello(name: String = "world"): String!
    #|}
    ),
    )
    // s.type_by_name("Query") carries the description and the default value.

    Schema::scalar

    fn Schema::scalar(self : Schema, name : String, serialize? : (Json) -> Json, parse_value? : (Json) -> Json, spec_url? : String, description? : String) -> Unit

    Register a custom scalar with its serialize / parse_value hooks. Both default to identity, which is enough for a scalar that only renames JSON it already carries (a DateTime stored as an ISO string, say).

    Schema::scalar_by_name

    fn Schema::scalar_by_name(self : Schema, name : String) -> ScalarType?

    Look up a registered custom scalar by name.

    Schema::set_mutation

    fn Schema::set_mutation(self : Schema, name : String) -> Unit

    Name the root mutation type; it must also be declared with object.

    Schema::set_subscription

    fn Schema::set_subscription(self : Schema, name : String) -> Unit

    Name the root subscription type; it must also be declared with object.

    Schema::to_sdl

    fn Schema::to_sdl(self : Schema) -> String

    Emit the schema as GraphQL SDL: a schema { query: ... } block, then one block per directive definition, then one block per composite type (type / input / interface, with implements and field arguments), then one block per enum, union and scalar type. Every element carries its description, its @deprecated(reason:), its arguments' default values and its applied directives, so that Schema::of_sdl reading this text back yields the same schema (§3).

    Schema::type_applied_directives

    fn Schema::type_applied_directives(self : Schema, type_name : String) -> Array[AppliedDirective]

    The directives applied to the type type_name.

    Schema::type_by_name

    fn Schema::type_by_name(self : Schema, name : String) -> ObjectType?

    Look up a declared composite type (object / input / interface) by name.

    Schema::type_has_directive

    fn Schema::type_has_directive(self : Schema, type_name : String, name : String) -> Bool

    Whether the type type_name carries the directive name.

    Schema::union

    fn Schema::union(self : Schema, name : String, members : Array[String], description? : String) -> Unit

    Declare a union type over the named member object types. Renders as union Name = A | B, preceded by description when one is given.

    Schema::union_by_name

    fn Schema::union_by_name(self : Schema, name : String) -> UnionType?

    Look up a declared union type by name.

    TypeKind

    pub(all) enum TypeKind {
    Object
    Input
    Interface
    } derive(Eq)

    Which kind of composite type an ObjectType describes: an output object (type), an input object, or an interface.

    TypeKind::equal

    fn TypeKind::equal(TypeKind, TypeKind) -> Bool

    TypeKind::not_equal

    fn TypeKind::not_equal(x : TypeKind, y : TypeKind) -> Bool

    UnionType

    pub(all) struct UnionType {
    name : String
    members : Array[String]
    description : String?
    }

    A GraphQL union type: a name and the ordered names of its member object types. A value at a union position is resolved to one member via its __typename, and only inline/named fragments on member types (plus __typename) may select into it.

    applied_directive_sdl

    fn applied_directive_sdl(d : AppliedDirective) -> String

    Render one applied directive to SDL: @name or @name(a: v, b: w).

    applied_directives_sdl

    fn applied_directives_sdl(ds : Array[AppliedDirective]) -> String

    Render a whole applied-directive list, each prefixed with a space (empty for an empty list), for appending after a field or type in SDL.

    builtin_exec_directive

    fn builtin_exec_directive(name : String) -> DirectiveDef?

    The definition of a built-in executable directive (@skip / @include), or None for a name that is not a built-in. The validator reads its locations and its if: Boolean! argument; the executor evaluates the directive itself, so no on_field hook is attached.

    description_sdl

    fn description_sdl(description : String?, indent? : Int) -> String

    Render a description as the SDL string literal that precedes the element it describes, followed by a newline — or the empty string when there is none (an empty description is the same thing as no description, which is how introspection reports it too). indent is the element's own indentation, in levels of two spaces.

    directive_def_sdl

    fn directive_def_sdl(d : DirectiveDef) -> String

    Render a directive definition to SDL: directive @name(a: A) repeatable onLOCATION | LOCATION. A definition is what a Schema::directive call registers; the places a directive is used are AppliedDirectives, which applied_directive_sdl renders.

    field_sdl

    fn field_sdl(f : Field) -> String

    Render a single field to SDL, including its argument list when non-empty, each argument's default value (= v), and its @deprecated(reason:). The description and the applied directives live on the schema, so they are the printer's job (see description_sdl and Schema::to_sdl), not this one's.

    introspection_type_def

    fn introspection_type_def(name : String) -> ObjectType?

    The synthetic definition of an introspection type by name, or None. These drive leaf-vs-composite completion when executing an introspection query.

    is_builtin_scalar

    fn is_builtin_scalar(name : String) -> Bool

    The five built-in scalar type names, which are leaves with no declaration.

    is_meta_field

    fn is_meta_field(name : String) -> Bool

    Whether name is an introspection meta-field (__-prefixed), which the spec forbids as a subscription root field.

    json_to_gql_literal

    fn json_to_gql_literal(j : Json) -> String

    Render a JSON value as a GraphQL literal, for printing an applied directive's arguments into SDL (@override(from: "accounts"), @key(fields: "id name")).

    kind_keyword

    fn kind_keyword(k : TypeKind) -> String

    The SDL keyword introducing a composite type of the given kind.

    type_sdl

    fn type_sdl(t : GqlType) -> String

    Render a type reference to GraphQL SDL notation (String!, [User!], ...).

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io