{"id":18116915,"url":"https://github.com/platypusrex/nextjs-plugin-graphql","last_synced_at":"2025-07-29T16:14:31.164Z","repository":{"id":45035780,"uuid":"447432168","full_name":"platypusrex/nextjs-plugin-graphql","owner":"platypusrex","description":"Next.js plugin to preprocess GraphQL Documents","archived":false,"fork":false,"pushed_at":"2023-10-26T13:13:44.000Z","size":411,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-29T23:25:00.878Z","etag":null,"topics":["graphql","nextjs","webpack"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nextjs-plugin-graphql","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/platypusrex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-01-13T02:06:09.000Z","updated_at":"2023-03-07T07:42:20.000Z","dependencies_parsed_at":"2024-10-09T13:45:32.939Z","dependency_job_id":null,"html_url":"https://github.com/platypusrex/nextjs-plugin-graphql","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platypusrex%2Fnextjs-plugin-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platypusrex%2Fnextjs-plugin-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platypusrex%2Fnextjs-plugin-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/platypusrex%2Fnextjs-plugin-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/platypusrex","download_url":"https://codeload.github.com/platypusrex/nextjs-plugin-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230479289,"owners_count":18232620,"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":["graphql","nextjs","webpack"],"created_at":"2024-11-01T04:17:16.208Z","updated_at":"2025-07-29T16:14:31.151Z","avatar_url":"https://github.com/platypusrex.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next.js + GraphQL Documents\n[![npm package](https://img.shields.io/npm/v/nextjs-plugin-graphql/latest.svg)](https://www.npmjs.com/package/nextjs-plugin-graphql)\n[![License](https://img.shields.io/npm/l/nextjs-plugin-graphql.svg)](https://github.com/platypusrex/nextjs-plugin-graphql/blob/master/LICENSE)\n\n[Next.js](https://github.com/zeit/next.js) plugin for preprocessing GraphQL Documents (operations, fragments and SDL)\n\n### Installation\n\nnpm\n\n```\nnpm add nextjs-plugin-graphql\n```\n\npnpm\n\n```\npnpm add nextjs-plugin-graphql\n```\n\nyarn\n\n```\nyarn add nextjs-plugin-graphql\n```\n### Usage\n\nCreate a `next.config.js` in your project\n\n```ts\n// next.config.ts\nimport type { NextConfig } from 'next';\nimport withGraphql from 'nextjs-plugin-graphql';\n\nconst nextConfig: NextConfig = {\n  reactStrictMode: true,\n};\n\nexport default withGraphql(nextConfig);\n```\n\nOptionally add Next.js configuration as a parameter\n\n```ts\n// next.config.ts\nimport type { NextConfig } from 'next';\nimport withGraphql from'nextjs-plugin-graphql';\n\nconst nextConfig: NextConfig = {\n  reactStrictMode: true,\n};\n\nexport default withGraphql({\n  reactStrictMode: true,\n  webpack(config, options) {\n    return config;\n  },\n});\n```\n\nAnd now in your components you can import `.graphql` | `.gql` files\n\n```graphql\nquery Users {\n  users {\n    id\n    name\n  }\n}\n```\n\n```js\nimport USERS_QUERY from './usersQuery.graphql';\n\nexport default async function Page() {\n  const data = await gqlClient.request(USERS_QUERY);\n  \n  return (\n    \u003cdiv\u003e\n      \u003cul\u003e\n        {data.users.map((user) =\u003e (\n          \u003cli key={user.id}\u003e\n            {user.name}\n          \u003c/li\u003e\n        ))}\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n### Options\n\n#### graphqlOptions\n\nThe plugins supports all available options of graphql-tools webpack loader.\nCheck out the [documentation](https://github.com/ardatan/graphql-tools/blob/3846041c14d0fe37d43b77156e2a0b85da8651ba/packages/webpack-loader/README.md) for the list of options.\n\nExample with options:\n\n```ts\nimport type { NextConfig } from 'next';\n\nconst nextConfig: NextConfig = {\n  reactStrictMode: true,  \n};\n\nexport default withGraphql({\n  ...nextConfig,\n  graphqlOptions: {\n    noDescription: true,\n    esModule: true,\n  },\n});\n```\n\n### Typescript\n\nTypescript is unable to interpret imported graphql files, so `nextjs-plugin-graphql` includes definitions\nfor graphql files (.graphql/.gql). Per the recommendations of the Next.js maintainers you\nshould not reference these types in the `next-env.d.ts` file. You can instead create a `typings`\ndirectory inside your `src` directory. Then simple create a definitions file (ie: `index.d.ts`) and \nreference the definitions there. There shouldn't be any need to adjust your `tsconfig.json` \nfor your project.\n\n`src/typings/index.d.ts`\n```ts\n/// \u003creference types=\"nextjs-plugin-graphql/types/graphql\" /\u003e\n```\n\n### Contributors\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## LICENSE\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplatypusrex%2Fnextjs-plugin-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplatypusrex%2Fnextjs-plugin-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplatypusrex%2Fnextjs-plugin-graphql/lists"}