{"id":16641789,"url":"https://github.com/samthor/duckql","last_synced_at":"2026-04-22T05:31:53.600Z","repository":{"id":57685949,"uuid":"487456317","full_name":"samthor/duckql","owner":"samthor","description":"🦆 DuckQL, untyped GraphQL server","archived":false,"fork":false,"pushed_at":"2022-05-03T21:49:28.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-26T09:06:40.388Z","etag":null,"topics":["graphql"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/duckql","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samthor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-01T05:46:29.000Z","updated_at":"2022-05-01T23:59:43.000Z","dependencies_parsed_at":"2022-09-18T23:21:45.414Z","dependency_job_id":null,"html_url":"https://github.com/samthor/duckql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/samthor/duckql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fduckql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fduckql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fduckql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fduckql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samthor","download_url":"https://codeload.github.com/samthor/duckql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fduckql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32122712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T00:31:26.853Z","status":"online","status_checked_at":"2026-04-22T02:00:05.693Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql"],"created_at":"2024-10-12T07:47:51.868Z","updated_at":"2026-04-22T05:31:53.577Z","avatar_url":"https://github.com/samthor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Tests](https://github.com/samthor/duckql/actions/workflows/node.js.yml/badge.svg)](https://github.com/samthor/duckql/actions/workflows/node.js.yml)\n\nDuckQL is an untyped GraphQL server that lets you write JS to resolve queries without a schema.\nIt's a useful layer to build custom resolvers or as a way of unifying other GraphQL servers.\n\n## Why?\n\nGraphQL is an overloaded concept.\nIt consists of two wholly unrelated parts:\n\n* a simple query language\n* a complex type system\n\nGraphQL queries don't know or care about the underlying types that they might resolve.\nFor example, take a list query:\n\n```gql\nquery Foo($filter: Filter!) {\n  listFoo(filter: $filter) {\n    items {\n      id\n      name\n      fooProp\n    }\n  }\n}\n```\n\nThis query knows nothing about what a `Foo` is, does not specify that `items` must be returned as a list, nor the `Filter` type we expect as a variable.\nYet, using Apollo requires us to specify a whole schema just to handle a request like this.\n\n## Usage\n\nDuckQL parses incoming GraphQL queries (via the core `graphql` package) and parses them into [a `ResolverContext` type](src/types.d.ts):\n\n```js\nimport { DuckQLServer } from 'duckql';\n\nconst gqlServer = new DuckQLServer({\n  resolver(context) {\n    const out = { data: {} };\n\n    if ('me' in context.selection.sub) {\n      out.data['me'] = { firstName: 'Sam', lastName: 'Thor' };\n    }\n\n    return out;\n  },\n});\n\nconst out = await gqlServer.handle({\n  query: `query { me { firstName lastName }}`,\n});\n```\n\n### Other Helpers\n\nDuckQL can also process a query synchronously into a `ResolverContext`:\n\n```js\nimport { buildContext } from 'duckql';\nconst context = buildContext({ query: `{ foo }` });\n```\n\nOr it can handle HTTP requests directly (on \"/graphql\" with method \"POST\"), using e.g., [Polka](https://github.com/lukeed/polka):\n\n```js\nimport polka from 'polka';\nimport { DuckQLServer } from 'duckql';\nconst gqlServer = new DuckQLServer({\n  resolver(context) { /* TODO */ },\n});\n\npolka()\n  .post('/graphql', gqlServer.httpHandle)\n  // or\n  .use(gqlServer.buildMiddlware())\n  .listen(3000);\n```\n\n### Variable Interpolation\n\nDuckQL interpolates any GraphQL variables it finds, like `$foo`.\nFor example, for a request like:\n\n```js\nconst request = {\n  variables: {\n    'x': 'hi!',\n  },\n  query: `query($x: String, $y: Number = 123) { listFoo(message: $x, size: $y) }`,\n}\n```\n\nThe processed selection of `listFoo` will already contain args `{ message: \"hi!\", size: 123 }`.\nMissing or unresolved variables are a parse error and will through `GraphQLQueryError` from this package.\n\n## API\n\nThe `ResolverContext` is an object which wraps up the selections of your query in a structured way.\nMost importantly, it has a property `selection`, which contains a recursive type `SelectionNode`:\n\n```ts\nexport type SelectionNode = {\n  args?: { [key: string]: GraphQLType };\n  directives?: any[];\n  sub?: SelectionSet;\n  node: FieldNode;\n};\nexport type SelectionSet = { [key: string]: SelectionNode };\n```\n\nFor example, if the user made a query for `{ listBar { bar(x: 123) { zing } } }`, then `context.selection` will look like:\n\n```js\n({\n  node: ...,\n  sub: {\n    'listBar': {\n      node: ...,\n      sub: {\n        'bar': {\n          node: ...,\n          args: { 'x': 123 },\n          sub: {\n            'zing': {\n              node: ...,\n            },\n          },\n        },\n      },\n    },\n  },\n})\n```\n\nImportantly, each sub-tree contains a node which can be used to reproduce a sub-tree of the original query.\nThis can be useful to forward these queries to another server _without_ having to care about the schema.\nFor example:\n\n```js\nimport { print } from 'graphql';\nconst q = print(context.sub['listBar'].sub['bar'].node);\nq === `bar(x: 123) {\n  zing\n}`;\n```\n\n### Other Context Properties\n\nAs well as the selection, the context also contains:\n\n* `operation`: one of 'query', 'mutation' or 'subscription'\n* `operationName`: the operation name in e.g., \"query Foo {\" would be \"Foo\", or the blank string for default/none\n* `maxDepth`: the maximum depth of selection (useful to catch abuse via deeply nested queries)\n* `node`: the original GraphQL AST node, _without_ variable interpolation\n\n## Missing Features\n\nDuckQL does not yet support:\n\n* Fragments: it will treat these as an invalid query\n* Directives: these are silently ignored, but remain in the AST to be forwarded\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fduckql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamthor%2Fduckql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fduckql/lists"}