moonbitstack/moongql/federation does not have a README file

    EntityResolver

    The reference resolver for an entity type: given a representation (a JSON object carrying __typename and the entity's key fields) and the request context, return the fully resolved entity as JSON. This is the subgraph's answer to "you have a key, give me the object" — Apollo's __resolveReference.

    EntityDef

    pub(all) struct EntityDef {
    name : String
    key : String
    extends : Bool
    external : Array[String]
    resolve : (
    Json
    ,
    Json
    ) ->
    Json
    raise
    ResolverError

    }

    One federated entity: its type name, the key field set (@key(fields:)), whether the subgraph only extends a type it does not own, the names of its external fields (@external, owned by another subgraph), and the reference resolver that materialises it from a representation.

    Federation

    pub struct Federation {
    entities : Array[EntityDef]
    v2 : Bool
    field_dirs : Array[(String, String,
    AppliedDirective
    )]
    type_dirs : Array[(String,
    AppliedDirective
    )]
    }

    The federation configuration for a subgraph: the set of entity types it contributes, whether it is a Federation v2 subgraph (which opts in with an @link to the federation spec and unlocks @shareable / @inaccessible / @override / @tag), and the type- and field-level federation directives it declares. Build it with new, register entities with entity, mark fields with shareable / inaccessible / override_ / requires / provides / tag, then apply it to a schema and resolver map.

    Federation::apply

    Install the federation machinery onto schema and resolvers: declare the _Any scalar, the _Service type with its sdl field, and the _Entity union over every registered entity type; add the _service and _entities fields to the query root; and register the two resolvers. After this the schema answers a federated query — { _service { sdl } } and _entities(representations:) — through the normal executor.

    Federation::check

    Everything a subgraph has to get right before a gateway can compose it: an @requires or @provides field set whose paths exist, the entity types the subgraph registers, and the directives it declares. Answers one line per problem, empty when there is none.

    @requires needs nothing at run time beyond what the executor already does — the gateway sends the named fields in the representation, and _entities keeps them on the value the entity resolver returned, so the resolver of the requiring field can read them. @provides needs nothing either: the fields are resolved here like any others, and this check is what lets the gateway rely on that.

    Federation::entity

    fn Federation::entity(self : Federation, name~ : String, key~ : String, resolve~ : (
    Json
    ,
    Json
    ) ->
    Json
    raise
    ResolverError
    , extends? : Bool, external? : Array[String]) -> Unit

    Register an entity type. name is the object type (which must also be declared on the schema), key is its @key field set ("id", or space- separated "upc sku" for a compound key), resolve turns a representation back into the object. Set extends when this subgraph extends a type owned by another, and list external fields that other subgraphs own.

    Federation::inaccessible

    fn Federation::inaccessible(self : Federation, type_name : String, field_name : String) -> Unit

    Mark type_name.field_name @inaccessible (v2) — present in this subgraph but omitted from the composed public schema, and hidden from introspection.

    Federation::new

    fn Federation::new(v2? : Bool) -> Federation

    An empty federation config. Pass v2=true for a Federation v2 subgraph, whose SDL opens with extend schema @link(...) importing the federation spec and which may use the v2-only directives (@shareable, @inaccessible, @override).

    Federation::override_

    fn Federation::override_(self : Federation, type_name : String, field_name : String, from~ : String) -> Unit

    Declare that type_name.field_name is @override-taken from the subgraph from (v2) — this subgraph now resolves the field the other used to own.

    Federation::provides

    fn Federation::provides(self : Federation, type_name : String, field_name : String, fields~ : String) -> Unit

    Declare that resolving type_name.field_name @provides the named fields of the returned entity, so the gateway can skip a round trip for them.

    Federation::requires

    fn Federation::requires(self : Federation, type_name : String, field_name : String, fields~ : String) -> Unit

    Declare that resolving type_name.field_name @requires the named external key fields ("weight size"), which the gateway then includes in the entity representation the _entities resolver receives.

    Federation::sdl

    Render the subgraph SDL: the schema as the developer wrote it, annotated with @key on entity types (prefixed extend when the type is an extension), @external on external fields, and with the federation-internal additions (_Service, _Entity, _Any, and the _service / _entities root fields) left out. This is what _service { sdl } returns.

    Federation::shareable

    fn Federation::shareable(self : Federation, type_name : String, field_name : String) -> Unit

    Mark type_name.field_name @shareable — resolvable by more than one subgraph (v2). Without it, a non-key field must be owned by exactly one subgraph.

    Federation::tag

    fn Federation::tag(self : Federation, type_name : String, name~ : String) -> Unit

    Mark the type type_name @tag(name: tag_name) (v2) — a label the router can filter or route by. @tag is repeatable, so a type may carry several.

    Federation::tag_field

    fn Federation::tag_field(self : Federation, type_name : String, field_name : String, name~ : String) -> Unit

    Mark type_name.field_name @tag(name: tag_name) (v2), repeatable like the type-level form.