{"id":21862560,"url":"https://github.com/0x31/bun-graphql-loader","last_synced_at":"2026-03-03T04:12:49.655Z","repository":{"id":253609490,"uuid":"829292439","full_name":"0x31/bun-graphql-loader","owner":"0x31","description":"A Bun plugin for loading GraphQL files. ","archived":false,"fork":false,"pushed_at":"2024-08-12T23:05:00.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-16T18:39:03.462Z","etag":null,"topics":["bun","bun-loader","bun-plugin","graphql","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/bun-graphql-loader","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0x31.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2024-07-16T06:30:08.000Z","updated_at":"2024-08-12T23:05:03.000Z","dependencies_parsed_at":"2024-08-18T06:51:27.215Z","dependency_job_id":null,"html_url":"https://github.com/0x31/bun-graphql-loader","commit_stats":null,"previous_names":["0x31/bun-graphql-loader"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x31%2Fbun-graphql-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x31%2Fbun-graphql-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x31%2Fbun-graphql-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x31%2Fbun-graphql-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0x31","download_url":"https://codeload.github.com/0x31/bun-graphql-loader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226851497,"owners_count":17692126,"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":["bun","bun-loader","bun-plugin","graphql","typescript"],"created_at":"2024-11-28T03:16:26.216Z","updated_at":"2026-03-03T04:12:49.615Z","avatar_url":"https://github.com/0x31.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bun-graphql-loader\n\n![License](https://img.shields.io/github/license/0x31/bun-graphql-loader?style=for-the-badge\u0026labelColor=2e3440\u0026color=6f4fbe)\n![Version](https://img.shields.io/npm/v/bun-graphql-loader.svg?label=Version\u0026style=for-the-badge\u0026labelColor=2e3440\u0026color=eea837)\n![Downloads](https://img.shields.io/npm/dw/bun-graphql-loader?style=for-the-badge\u0026labelColor=2e3440\u0026color=50b6a9)\n![Bun Badge](https://img.shields.io/badge/Bun-000?logo=bun\u0026logoColor=fff\u0026style=for-the-badge\u0026color=2e3440)\n![GraphQL Badge](https://img.shields.io/badge/GraphQL-E10098?logo=graphql\u0026logoColor=fff\u0026style=for-the-badge\u0026color=ee4367)\n![TypeScript Badge](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript\u0026logoColor=fff\u0026style=for-the-badge)\n\nA Bun plugin for loading GraphQL .gql and .graphql files, using on [graphql-tag](https://github.com/apollographql/graphql-tag). Based on [vite-plugin-graphql-loader](https://www.npmjs.com/package/vite-plugin-graphql-loader).\n\n## Install\n\n```bash\nbun add --dev bun-graphql-loader\n```\n\n## Usage\n\nCalling `Bun.build`:\n\n```typescript\nimport bunGraphqlLoader from 'bun-graphql-loader';\n\nawait Bun.build({\n    ...\n    plugins: [\n        ...\n        bunGraphqlLoader(),\n        ...\n    ],\n    ...\n});\n```\n\nUsing with `bun test`:\n\nCreate a file called `bunGraphqlLoader.ts` with the following content:\n\n```ts\nimport bunGraphqlLoader from \"bun-graphql-loader\";\nimport { plugin } from \"bun\";\n\nplugin(bunGraphqlLoader());\n```\n\nAnd add it to your `bunfig.toml` (customizing the path if necessary):\n\n```toml\n[test]\npreload = [\n  \"./bunGraphqlLoader.ts\",\n]\n```\n\nNow you can import queries from `.gql` or `.graphql` files.\n\n`example.graphql`:\n\n```graphql\n#import \"./ExampleImport.graphql\"\n\nfragment ExampleFragment on example {\n    id\n    name\n}\n\nquery ExampleQuery {\n    example {\n        ...ExampleFragment\n        ...ExampleImport\n    }\n}\n```\n\n`example.js`:\n\n```javascript\nimport ExampleQuery, { ExampleFragment } from \"./example.graphql\";\n```\n\nIf you have multiple queries in the same file, import them like this:\n\n```javascript\nimport { FirstQuery, SecondQuery } from \"./example.graphql\";\n```\n\n## TypeScript\n\nIf you are using TypeScript, you will have to declare `.gql` or `.graphql` files.\n\nCreate `graphql.d.ts` anywhere in your source directory and\n\n```typescript\ndeclare module \"*.gql\";\ndeclare module \"*.graphql\";\n```\n\n**_Alternatively_**, change it to this (replacing .gql with .graphql depending on what you use):\n\n```typescript\ndeclare module \"*.gql\" {\n    const Query: import(\"graphql\").DocumentNode;\n    export default Query;\n    export const _queries: Record\u003cstring, import(\"graphql\").DocumentNode\u003e;\n    export const _fragments: Record\u003c\n        string,\n        import(\"graphql\").FragmentDefinitionNode\n    \u003e;\n}\n```\n\nAnd then import fragments and queries like so in order to type them as `DocumentNode` and `FragmentDefinitionNode` objects.\n\n```typescript\nimport Document, { _queries, _fragments } from \"./example.graphql\";\nconsole.log(Document); // Has type `DocumentNode`\nconsole.log(_queries.ExampleQuery); // Has type `DocumentNode`\nconsole.log(_fragments.ExampleFragment); // Has type `FragmentDefinitionNode`\n```\n\n## Changelog\n\n**_v1.0.0_**:\n\n-   Adapted from [vite-plugin-graphql-loader](https://www.npmjs.com/package/vite-plugin-graphql-loader).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x31%2Fbun-graphql-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0x31%2Fbun-graphql-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x31%2Fbun-graphql-loader/lists"}