forgo.cloud
Sign in
Repo workspace

forkjoin-ai/x-gql

x-gql

README.md
forkjoin-ai/x-gql

x-gql

Parent: Open-Source Ecosystem

@a0n/x-gql projects Gnosis .gg topologies into GraphQL execution surfaces. It turns a topology file into GraphQL SDL, a runtime GraphQLSchema, Apollo and GraphQL Yoga adapters, OpenAPI/Postman exports, Worker fetch handlers, and federation/runtime-IO query layers.

The important boundary is that GraphQL is a projection layer, not the authority. The .gg topology remains the source structure. x-gql gives conventional GraphQL clients a typed entry point into that topology while preserving the fork/race/fold semantics, UCAN capability annotations, federation proofs, runtime continuation state, and mesh-policy gates that live below GraphQL.

Stack context: Gnosis, x-gnosis, and x-gql. Source map: src/README.md.

Why It Matters

GraphQL normally starts from application schema design. In this stack, schema design is downstream of topology. A .gg file already encodes process edges, folds, races, forks, vents, options, variants, and authorization metadata. x-gql projects those objects into the GraphQL tools that teams already know without making GraphQL the canonical model.

That changes the failure mode. If the SDL, OpenAPI document, Postman collection, Apollo server, Yoga server, Worker handler, and federation queries all come from the same topology source, drift becomes easier to detect. The question changes from "did someone update every API artifact?" to "does this projection still preserve the topology contract?"

Projection Ledgers

Ledger Runtime objects
Topology-to-schema GGL nodes, properties, edges, variants, result types, GraphQL SDL.
Operation projection PROCESS to queries, FOLD to mutations, FORK to subscriptions, RACE to unions, VENT to nullable/error surfaces.
Runtime execution GraphQLSchema, resolver map, executeOperation(), fetch-compatible Yoga server.
Transport adapters Apollo Server, Apollo Express middleware, Apollo Fastify plugin, Yoga Node/http helpers.
Export surfaces GraphQL SDL, OpenAPI 3.1, Postman collection.
Federation projection Signed snapshot, N1 lookup, route proof, chain record queries.
Runtime IO projection mutate/query/subscribe/poll/gate/workflow/pause/handoff/resume/resolve surfaces.
Worker gate Web Fetch handler, /graphql and /health routing, compiled mesh-policy wrapper.
Observability Optional OpenTelemetry spans and Datadog OTLP resolution through @a0n/telemetry.

Domain Map

Domain What x-gql provides
Schema generation generateSchema(), schemaToGraphQL(), schemaToOpenAPI(), and schemaToPostman().
Local GraphQL execution createGqlServer() with generated schema, resolvers, SDL export, and direct operation execution.
Apollo compatibility Real Apollo Server construction plus Express and Fastify adapter glue.
GraphQL Yoga compatibility Real Yoga server construction, fetch adapter, Node request listener, and HTTP server helper.
Worker deployment createXGqlWorker() and wrapWithXGqlMesh() for Web Fetch runtimes behind mesh policy.
Knot federation buildFederationProjectionLayer() for signed federation chain, lookup, and snapshot projection.
Runtime IO buildRuntimeIoProjectionLayer() for DTN mutation, query, subscription, workflow, and continuation lifecycle.
Tracing initXGqlTracingFromEnv(), isXGqlTracingEnabled(), withXGqlSpan(), and xGqlTracer.

GGL To GraphQL Mapping

GGL concept GraphQL projection
Node with labels Type with fields
Node properties Field arguments or input types
PROCESS edge Query resolver
FOLD edge Mutation
FORK edge Subscription stream
RACE edge Union type
VENT edge Nullable field or error surface
Result, Option, Variant Union, nullable field, or enum
Destructure Fragment or inline spread
Topology file Schema module and export bundle

Public API

Export Purpose
generateSchema() Convert a Betty/Gnosis graph AST into an x-gql schema model.
schemaToGraphQL() Emit GraphQL SDL from the schema model.
schemaToOpenAPI() Emit an OpenAPI 3.1 document from the same topology projection.
schemaToPostman() Emit a Postman collection from the same topology projection.
createGqlServer() Build the executable GraphQL runtime with SDL, schema, resolvers, exports, and adapters.
createApolloServer() Wrap the x-gql schema in a real Apollo Server.
createApolloExpressMiddleware() Mount Apollo execution into Express-compatible middleware.
createApolloFastifyPlugin() Mount Apollo execution into a Fastify plugin.
createYogaServer() Wrap the x-gql schema in a real GraphQL Yoga server.
createYogaHttpServer() Build a Node HTTP server for a Yoga instance.
createYogaNodeRequestListener() Build a Node request listener for Yoga.
createXGqlWorker() Build a mesh-gated Web Fetch handler for Worker deployments.
wrapWithXGqlMesh() Apply the same compiled mesh-policy gate to a custom fetch handler.
buildFederationProjectionLayer() Project knot federation chain, lookup, and snapshot records into GraphQL.
buildRuntimeIoProjectionLayer() Project runtime mutation, subscription, workflow, and continuation IO into GraphQL.
initXGqlTracingFromEnv() Enable optional tracing from environment configuration.

Proof And Runtime Boundaries

Claim type Status
.gg to GraphQL schema projection Implemented and tested in gg-to-graphql.ts and server tests.
Apollo and GraphQL Yoga compatibility Implemented with direct server wrappers and transport helper tests.
Federation projection Implemented with route/snapshot verification and fail-closed tests.
Runtime IO projection Implemented with mutation/query/subscription/workflow/continuation tests.
Worker mesh gate Implemented with inner fetch and mesh-gated Worker tests.
Formal topology authority Lives in Gnosis; x-gql projects it but does not replace it.
Production authorization policy UCAN and mesh policy are surfaced here; host applications still own policy data, keys, and resolver behavior.

Examples

Generate And Execute From Topology

import { createGqlServer } from '@a0n/x-gql';

const server = createGqlServer({
  topologies: ['./app.gg'],
  resolvers: {
    Query: {
      scanResult: async (_source, args) => {
        return { id: args.repo, status: 'complete' };
      },
    },
  },
});

const result = await server.executeOperation({
  query: 'query Scan($repo: String!) { scanResult(repo: $repo) { id status } }',
  variables: { repo: 'x-gql' },
});

console.log(server.toGraphQLSDL());
console.log(result.data);

Export SDL, OpenAPI, And Postman

import { createGqlServer } from '@a0n/x-gql';

const server = createGqlServer({
  topologies: ['./app.gg'],
  name: 'Topology API',
  baseUrl: 'https://api.example.test',
});

const sdl = server.toGraphQLSDL();
const openapi = server.toOpenAPI();
const postman = server.toPostmanCollection();

console.log(sdl);
console.log(openapi);
console.log(postman);

Apollo And Yoga Transports

import express from 'express';
import Fastify from 'fastify';
import { createServer } from 'node:http';
import {
  createApolloExpressMiddleware,
  createApolloFastifyPlugin,
  createApolloServer,
  createYogaHttpServer,
  createYogaNodeRequestListener,
  createYogaServer,
} from '@a0n/x-gql';

const apollo = createApolloServer({ topologies: ['./app.gg'] });
const yoga = createYogaServer(
  { topologies: ['./app.gg'], graphqlEndpoint: '/graphql' },
  { landingPage: false }
);

const expressApp = express();
expressApp.use(express.json());
expressApp.use('/graphql', await createApolloExpressMiddleware(apollo));

const fastifyApp = Fastify();
await fastifyApp.register(
  createApolloFastifyPlugin(apollo, { path: '/graphql' })
);

const yogaHttpServer = createYogaHttpServer(yoga);
const yogaListenerServer = createServer(createYogaNodeRequestListener(yoga));

console.log(Boolean(yogaHttpServer));
console.log(Boolean(yogaListenerServer));

Worker Fetch Handler

import { createXGqlWorker } from '@a0n/x-gql/worker';

const worker = createXGqlWorker({
  gql: {
    source: `
      (Scan:Result { status: "String" })
      (Request)-[:PROCESS { auth: "scan/read" }]->(Scan)
    `,
    graphqlEndpoint: '/graphql',
  },
});

export default { fetch: worker };

Federation Projection

import {
  buildFederationProjectionLayer,
  createGqlServer,
} from '@a0n/x-gql';

const federation = buildFederationProjectionLayer({
  federationChain: async (id) => lookupChainRecord(id),
  federationLookup: async (from, to) => lookupRoute(from, to),
  federationSnapshot: async () => currentSignedSnapshot(),
  issuerPublicKeys,
});

const server = createGqlServer({
  schema: federation.schema,
  resolvers: federation.resolvers,
});

const result = await server.executeOperation({
  query: '{ federationSnapshot { epoch digest recordCount } }',
});

console.log(result.data);

Optional Tracing

x-gql supports optional tracing for direct fetch handlers and Apollo Express/Fastify adapters through @a0n/telemetry.

  • Enable explicitly with X_GQL_TRACING_ENABLED=true.
  • Or auto-enable by setting OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.
  • Datadog agentless OTLP can be resolved from DD_API_KEY plus DATADOG_SITE or DD_SITE.
  • Debug spans can be printed with DEBUG_TELEMETRY=true.

CLI

# Generate GraphQL SDL from .gg
gnode x-gql generate ./app.gg --out schema.graphql

# Generate OpenAPI spec
gnode x-gql openapi ./app.gg --out openapi.json

# Generate Postman collection
gnode x-gql postman ./app.gg --out collection.json

# Serve GraphQL playground
gnode x-gql serve ./app.gg --port 4000

Architecture

.gg topology --> Betty compiler --> Graph AST --> x-gql projection
                                                   |-- GraphQL SDL
                                                   |-- GraphQLSchema
                                                   |-- OpenAPI 3.1
                                                   |-- Postman collection
                                                   |-- Apollo Server
                                                   |-- Apollo Express/Fastify
                                                   |-- GraphQL Yoga
                                                   |-- Node http helpers
                                                   |-- Worker fetch handler
                                                   |-- federation projection
                                                   |-- runtime IO projection

Development

Source files live in src. Focused test coverage lives in src/tests.

Use the repository-owned a0 target from the monorepo root:

pnpm run a0 -- run @a0n/x-gql:test
pnpm run a0 -- run @a0n/x-gql:typecheck
pnpm run a0 -- run @a0n/x-gql:lint

For README-only changes, validate local Markdown links and keep the parent and child README links intact.