Homoiconic GraphQL schema builder, query/mutation/fragment parser, N+1 batching Dataloader, introspection, and HTML5 GraphiQL Explorer.
Zero-codegen homoiconic GraphQL engine, recursive-descent document parser, __schema introspection, batching Dataloader, and Light-First HTML5 GraphiQL Explorer for web/App.
graphql implements a complete, dependency-free GraphQL server and query engine in pure Veko:
graphql/parser: Spec-compliant GraphQL lexer and recursive-descent parser (tokenize-gql, parse-document) supporting query, mutation, subscription, shorthand { ... } queries, operation names, typed variable definitions with defaults ($id: ID! = "1"), field aliases (primary: user(...)), rich argument literals (ints, floats, strings, """...""" block strings, booleans, null, enums, nested lists, input objects, and $var references), @include(if: ...) and @skip(if: ...) directives, named fragments (...UserFields), and inline fragments (... on User { ... }).graphql: Imperative and homoiconic (from-quote) schema builders (new-schema, define-object, define-enum, field, query-field, mutation-field), spec-compliant execute with Non-Null error bubbling, built-in __typename, __schema, and __type introspection, N+1 batching and per-request caching Dataloader (new-dataloader, load-one, load-many), and one-line mount-graphql integration for web/App serving both POST /graphql and a Light-First zero-CDN HTML5 GraphiQL Explorer on GET /graphql.veko pkg add graphql@1.0.0Import the engine and parser modules:
use [
gql = graphql
parser = graphql/parser
web
]from-quote): Define enums, object types, field arguments, Non-Null modifiers, and root query/mutation operations directly inside a native Veko quote [...] block paired with a 'Type.field' resolver map—eliminating external SDL code generation steps.execute implements GraphQL's CollectFields selection merging across aliases, @skip/@include directives, named fragment spreads (with cycle protection), and type-conditioned inline fragments. Resolver errors record exact response path arrays and bubble .null cleanly across non-nullable (!) boundaries.Dataloader Batching: load-many deduplicates requested keys, skips keys already present in the per-request cache, dispatches at most one batch_fn call for missing keys, and returns values aligned 1:1 with the caller's input key list.mount-graphql serves an embedded HTML5 Explorer (data-theme="light" default with persistent localStorage Dark Mode toggle, Ctrl+Enter execution, JSON variables pane, and Lightbox Schema Introspection modal) with zero external CDN requests.graphql/parser| Type / Signature | Description |
|---|---|
GqlDocument = struct { operations block[GqlOperation], fragments map } | Parsed GraphQL executable document AST. |
GqlOperation, GqlFragment, GqlFieldSel, GqlFragSpread, GqlInlineFrag, GqlVarDef, GqlDirective | Typed AST nodes for operations, fragments, selections, variables, and directives. |
tokenize-gql = fn [src str] block[GqlTok] | Lexical scanner ignoring # comments and insignificant commas. |
parse-document = fn [src str] GqlDocument | Parses a GraphQL query/mutation document string into GqlDocument. |
graphql| Type / Signature | Description |
|---|---|
Schema, ObjectDef, EnumDef, FieldDef | Executable GraphQL schema and type definitions. |
Dataloader = struct { batch_fn any, cache map, batch_calls i64, cache_hits i64 } | Per-request batching and memoizing loader. |
new-schema = fn [] Schema | Creates an empty GraphQL schema with a Query root object. |
field = fn [name str, type_str str /args args map = {} /resolve resolver any = .none /desc description str = ''] FieldDef | Defines an object field (defaults to reading parent.<name> when resolver == .none). |
define-enum = fn [mut schema Schema, name str, values block[str] /desc description str = ''] enum | Registers a GraphQL ENUM type. |
define-object = fn [mut schema Schema, name str, fields block[FieldDef] /desc description str = ''] enum | Registers a GraphQL OBJECT type. |
query-field / mutation-field | Registers a root field on Query or Mutation. |
from-quote = fn [dsl block, resolvers map] Schema | Builds an executable Schema from a homoiconic quote [...] block and 'Type.field' resolver map. |
execute = fn [schema Schema, doc_str str, variables map, ctx any /operation_name op_name str = ''] map | Executes a GraphQL operation and returns { data = ..., errors = [...] }. |
new-dataloader = fn [batch_fn any] Dataloader | Creates a Dataloader around `fn [keys block] block |
load-many = fn [mut loader Dataloader, keys block] block / load-one = fn [mut loader Dataloader, key any] any | Batches and caches key lookups deterministically. |
prime-dataloader / clear-dataloader | Seeds or clears a Dataloader's per-request cache. |
mount-graphql = fn [mut app web/App, path str, schema Schema /ctx_fn make_ctx any = .none /title explorer_title str = 'Veko GraphQL Explorer'] enum | Mounts POST <path> and GET <path> Explorer onto web/App. |
use [gql = graphql, web]
schema = gql/from-quote (quote [
object User [ id ID!, name String! ]
query [ user [id ID!] User ]
]) {
'Query.user' = fn [_p any, args map, _ctx any] any [
{ id = (map/get args 'id'), name = 'Ada Lovelace' }
]
}
res = gql/execute schema 'query($id: ID!) { u: user(id: $id) { __typename id name } }' { id = 'u-1' } {}
println (json/encode res.data)
mut app = web/new-app
_ = gql/mount-graphql mut app '/graphql' schemaveko check packages/graphql/src/parser.vk
veko check packages/graphql/src/mod.vk
veko check packages/graphql/examples/demo.vk
veko run -C all packages/graphql/examples/demo.vkhttps://veko-lang.org/pkg/graphql/1.0.0.vkp7f6079ddbaa0045782e7fdbd492bd69225e0aa8f4dca0c7a3f7f6950e7a538cee7eb491b1df8b7446d25eb765738d698cb631346a7d9f37791fa37f4f29eba65ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70{"name":"graphql","version":"1.0.0","tier":4.0,"tier_label":"Tier 4: FinTech, GraphQL, CDP & SSO","category":"Zero-Codegen GraphQL & Dataloader","description":"Homoiconic GraphQL schema builder, query/mutation/fragment parser, N+1 batching Dataloader, introspection, and HTML5 GraphiQL Explorer.","modules":["graphql","graphql/parser"],"homepage":"https://veko-lang.org/packages/graphql"}| Bundle Entry Path | Size | Leaf SHA-256 Digest |
|---|---|---|
| README.md | 5 KB | 4d8cdb07273fea9b24444d5bd08d046c96946e6eeb8dd88bc1bb55e460f8a105 |
| examples/demo.vk | 10 KB | 7d37d92e94ce3ebf541dac73cb68e7c11e72cd19237e107ebee57a4a578c744f |
| mod.vk | 34 KB | b59ead17364d37a2648d4a0a6061ce9d590592b8f792802aa3d629e393d96fd1 |
| parser.vk | 18 KB | 264d5278389630e1c36b4234370336740a892a99e46d1b7c8f7b77fde9519cb1 |