{"id":26064588,"url":"https://github.com/danielc92/graph-schema-to-query-templates","last_synced_at":"2025-03-08T18:41:34.712Z","repository":{"id":131065883,"uuid":"610628835","full_name":"danielc92/graph-schema-to-query-templates","owner":"danielc92","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-04T05:30:10.000Z","size":89,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T06:39:26.911Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielc92.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-07T06:45:43.000Z","updated_at":"2023-03-07T06:51:49.000Z","dependencies_parsed_at":"2024-01-03T10:50:23.463Z","dependency_job_id":"fde4c84d-f472-4452-bbb9-bfd99fea5aa7","html_url":"https://github.com/danielc92/graph-schema-to-query-templates","commit_stats":{"total_commits":33,"total_committers":2,"mean_commits":16.5,"dds":"0.030303030303030276","last_synced_commit":"bc2a173474974cfff0af644730f667733bb0a862"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielc92%2Fgraph-schema-to-query-templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielc92%2Fgraph-schema-to-query-templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielc92%2Fgraph-schema-to-query-templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielc92%2Fgraph-schema-to-query-templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielc92","download_url":"https://codeload.github.com/danielc92/graph-schema-to-query-templates/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242483273,"owners_count":20135784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-03-08T18:41:33.129Z","updated_at":"2025-03-08T18:41:34.700Z","avatar_url":"https://github.com/danielc92.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graph-schema-to-query-templates\n\nThis repo contains code that enables conversion of graphql schema files (.gql / .graphql) into query template strings.\n\n### Notes\n- Supports mjs and cjs imports\n- Supports **nested** queries and mutation types, if `searchTokens` is provided\n- Currently supports building templates from Mutation and Query types. Templates are built recursively.\n\n### Usage Example\n\nInstallation\n\n```\nnpm i graphql-schema-to-query\n```\n\nFor example with a schema file `test.graphql`\n```\ntype Query {\n    foo: String\n    bar: Int\n    animals: AnimalQueries\n}\n\ntype AnimalQueries {\n    birds: BirdQueries\n    getAnimals(names: [String!]!): [Animal]\n\n}\n\ntype BirdQueries {\n    parrot: String\n    chicken: String\n    birdsWithFeathers: [Animal]\n}\n\ntype Animal {\n    name: String\n    species: String\n}\n\ntype Mutation {\n    updateBird(id: String): Animal\n}\n```\nSet your input, output paths and serviceName, then call buildCollection and exportCollection.\n\n```js\nimport {GqlToTemplate} from 'graphql-schema-to-query'\n\nnew GqlToTemplate({\n  // Link to your source .gql or .graphql file\n  inputPath: \"output/test.graphql\",\n  // Link to folder where files will be saved\n  outputPath: \"output\",\n  // Name of your service, this is arbitrary but should not contain hyphens\n  serviceName: \"BIRD_SERVICE\",\n  // defaults to [\"query\", \"queries\", \"mutation\", \"mutations\"]\n  //   searchTokens: []\n})\n  .buildCollection()\n  .exportCollection({\n    // js or ts\n    extension: \"ts\",\n    // logs templates\n    debug: true\n  })\n```\n\nProduces the following files in the output folder\n```\nBIRD_SERVICE__bar.ts\nBIRD_SERVICE__birdsWithFeathers.ts\nBIRD_SERVICE__chicken.ts\nBIRD_SERVICE__foo.ts\nBIRD_SERVICE__getAnimals.ts\nBIRD_SERVICE__parrot.ts\nBIRD_SERVICE__updateBird.ts\n```\n\nwith the following contents\n```\n\nexport const template = `query BIRD_SERVICE____foo {foo }`\nexport const template = `query BIRD_SERVICE____bar {bar }`\nexport const template = `query BIRD_SERVICE__animals__birds__parrot {animals { birds { parrot  } }}`\nexport const template = `query BIRD_SERVICE__animals__birds__chicken {animals { birds { chicken  } }}`\nexport const template = `query BIRD_SERVICE__animals__birds__birdsWithFeathers {animals { birds { birdsWithFeathers {name  species } } }}`\nexport const template = `query BIRD_SERVICE__animals__getAnimals($names: [String!]!) {animals { getAnimals(names: $names) {name  species } }}`\nexport const template = `mutation BIRD_SERVICE____updateBird($id: String) {updateBird(id: $id) {name  species }}`\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielc92%2Fgraph-schema-to-query-templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielc92%2Fgraph-schema-to-query-templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielc92%2Fgraph-schema-to-query-templates/lists"}