{"id":47110979,"url":"https://github.com/deref/extractgqlts","last_synced_at":"2026-03-12T17:43:57.788Z","repository":{"id":132972423,"uuid":"468943023","full_name":"deref/extractgqlts","owner":"deref","description":"Extracts TypeScript types from GraphQL string literals","archived":false,"fork":false,"pushed_at":"2022-03-25T16:47:59.000Z","size":60,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-21T18:46:04.261Z","etag":null,"topics":["code-generator","graphql","types","typescript"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deref.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-12T00:54:23.000Z","updated_at":"2022-10-21T19:35:59.000Z","dependencies_parsed_at":"2024-02-13T12:00:25.833Z","dependency_job_id":null,"html_url":"https://github.com/deref/extractgqlts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/deref/extractgqlts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deref%2Fextractgqlts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deref%2Fextractgqlts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deref%2Fextractgqlts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deref%2Fextractgqlts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deref","download_url":"https://codeload.github.com/deref/extractgqlts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deref%2Fextractgqlts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30435814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T14:34:45.044Z","status":"ssl_error","status_checked_at":"2026-03-12T14:09:33.793Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["code-generator","graphql","types","typescript"],"created_at":"2026-03-12T17:43:57.208Z","updated_at":"2026-03-12T17:43:57.772Z","avatar_url":"https://github.com/deref.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# extractgqlts - Extract GraphQL TypeScript\n\nGenerates TypeScript types from GraphQL usage in string literals.\n\nThis code generation tool is intended to be extremely fast to execute.\nAdditionally, strong conventions make it uncomplicated to use.\n\n## Status\n\n**STABILIZING**\n\nYou are likely to encounter small problems using this. However, it being used\nsuccessfully by an in-development product now, so it does indeed work.\n\nFeedback and/or contributions welcome.\n\n## Install\n\nCurrently only distributed as a Go module:\n\n```bash\ngo get github.com/deref/extractgqlts\n```\n\n## Usage\n\nWrite queries in your code using string literals with the following prefix:\n\u003ccode\u003e`#graphql\u003c/code\u003e. For example:\n\n```typescript\nconst { query } = './example/graphql';\n\nconst profileFragment = `#graphql\n  fragment Profile on Named {\n    name\n  }\n`\n\nconst query(`#graphql\n  {\n    node(id: $id) {\n      id\n      ...Profile\n    }\n  }\n`, {\n  include: [profileFragment],\n});\n```\n\nRun the code generator, something like this:\n\n```bash\nextractgqlts \\\n  --schema ./src/graphql/schema.gql \\\n  './src/components/{tsx,svelte}' \\\n  \u003e ./src/graphql/types.generated.ts\n```\n\nThe generated output contains a mapped type called `QueryTypes`. This maps\nquery strings to `{ data, variables }` structures for use in whatever driver\nfunctions you supply yourself. For a simple example:\n\n```typescript\nimport { QueryTypes } from './types.generated.ts';\n\nconst query = \u003cTQuery extends keyof QueryTypes\u003e(\n  query: TQuery,\n  variables: QueryTypes[TQuery]['variables'],\n): Promise\u003cQueryTypes[TQuery]['data']\u003e =\u003e {\n  // ...\n}\n```\n\nA more complete example can be found in [this\ngist](https://gist.github.com/brandonbloom/0b2373f43d4c11f83bde3dcb61974622)\nextracted from a Svelte project.\n\nIf you have custom scalars, you'll also need `./src/graphql/scalars.ts`.\n\n## Design Constraints \u0026 Implementation Notes\n\n### Queries Live in Component Files\n\nIt should not require many, many files to define a single UI Component. GraphQL\nqueries must appear in the one and only component file.\n\n### No Manual Type Imports\n\nGiven a global schema, the query string itself should be sufficient to\ndetermine the data and variable types. You shouldn't need to give the query an\nexplicit name and then laborously import a type based on that name. Until\nTypeScript offers [type providers](https://github.com/microsoft/TypeScript/issues/3136),\nthe only way to do this without a manual import is to use a [mapped\ntype](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html) keyed\nby the query string.\n\n### Framework Agnostic\n\nDoes not assume React, Apollo, or anything else.\n\nThis means you must provide your own entrypoint to the generated types that\nindexes the `QueryTypes` map.\n\n### Convention Over Configuration\n\nThe assumption is that you will have one module directory that will contain\nthree code files:\n\n- `./types.generated.ts` - The generated output of the `extractgqlts` tool.\n  Note, this name is not (yet?) enforced.\n- `./scalars.ts` - Exports scalar types to be imported by `./types.generated.ts`.\n- `./index.ts` - Consumes the generated types and exports exposes your\n  framework-specific entrypoints.\n\n### Global Names\n\nAssumes there is one global namespace of query and fragment names in your\napplication. If you violate this, you'll get a TypeScript error regarding a\nduplicate identifier.\n\n### No TypeScript Parsing\n\nExtracts GraphQL documents from TypeScript files by scanning for\n\u003ccode\u003e`#graphql\u003c/code\u003e. This character sequence starts a JavaScript string\nliteral that is assumed to contain a GraphQL document. This pattern is also\nrecognized by common IDE plugins, such as [the most popular one for VS\nCode](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql).\n\nNote, we look for a string literal and not a \u003ccode\u003egql`\u003c/code\u003e template literal\ntag because of a [TypeScript\nlimitation](https://github.com/microsoft/TypeScript/issues/33304).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderef%2Fextractgqlts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderef%2Fextractgqlts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderef%2Fextractgqlts/lists"}