$ show graphql-editor/graphql-zeus
GraphQL Zeus is a TypeScript-first GraphQL client generator that produces a fully type-safe query builder from any GraphQL schema. It provides a CLI tool (`zeus`) that accepts a GraphQL schema file or introspection URL and generates a complete TypeScript client with zero runtime dependencies beyond `cross-fetch` and `ws` (for subscriptions). The generated client supports multiple transport modes: standard HTTP via `Chain` and `Thunder` (with custom fetch injection), WebSocket subscriptions (both legacy and `graphql-ws`), and Server-Sent Events (SSE). It also offers integration helpers for Apollo Client (`typedDocumentNode`) and exports reusable selection set composition via `Selector`. The monorepo is structured into three packages: `graphql-zeus` (CLI orchestration), `graphql-zeus-core` (code generation engine and runtime functions), and `graphql-zeus-jsonschema` (JSON Schema generation from input types). The code generation pipeline parses the schema into a tree structure, then templates it into TypeScript types and runtime functions. The project is moderately well-maintained with active issues and a test suite focused on the core code generator, though the CLI lacks automated tests and the build tooling relies on the deprecated `ttypescript` package, indicating some technical drift.
The LLM identified 7 files worth highlighting for reuse:
Defines the primary runtime exports (`Chain`, `Thunder`, `Subscription`, `Zeus`, `Selector`, `fields`, `ZeusScalars`, `$`). `Chain` and `Thunder` are the main query/mutation clients that build request payloads from selection sets and execute them via HTTP. The `Thunder` pattern allows users to inject a custom fetch function (e.g., for auth headers, retries), while `Chain` uses a default fetch. Both provide end-to-end type inference from schema to response. This module is self-contained and demonstrates a clean pattern for building type-safe API clients.
Implements the core query string construction from the internal tree representation. It recursively builds the GraphQL query document string based on the selection set structure and variables. This function is isolated from the rest of the system (depends only on internal types and `purifyGraphQLKey`) and could be reused to generate GraphQL queries from a selection tree in other contexts.
Provides a generic mechanism to decode custom scalars from API responses. It uses a path map (`PrepareScalarPaths`) and a user-provided `ZeusScalars` configuration to transform scalar values (e.g., Date strings to Date objects). The logic is parameterized and self-contained, making it reusable in any GraphQL client that needs runtime scalar conversion.
Exports `resolverFor` which generates a type-safe resolver factory for creating GraphQL resolver mocks or implementations. It leverages the generated `ResolverInputTypes` to provide full autocompletion for resolver arguments. This pattern is useful for testing or building GraphQL servers with type safety.
Contains the `$` helper function and the `ExtractVariables` type utility for declaring and inferring GraphQL variable types. `$('name', 'String!')` creates a typed variable reference, and `ExtractVariables` extracts the variable types from a query's arguments. This is a small but clever pattern for embedding variable definitions in a type-safe way without a separate declaration file.
Implements an SSE subscription client using the Fetch API's `ReadableStream` and `AbortController`. It parses SSE events, handles reconnection, and returns an async iterable. This is a standalone, reusable implementation of GraphQL over SSE that does not depend on any external libraries (only `cross-fetch`). It demonstrates a clean pattern for streaming subscriptions.
Generates TypeScript code for a GraphQL field in the output client, handling aliases, arguments, and nested selections. This template function is one of the building blocks of the code generator. It is pure (input tree node -> output string) and could be reused in other code generation projects that need to emit GraphQL selection set code.