{"id":13727029,"url":"https://github.com/correttojs/graphql-codegen-apollo-next-ssr","last_synced_at":"2025-05-15T10:05:43.989Z","repository":{"id":37031238,"uuid":"273730038","full_name":"correttojs/graphql-codegen-apollo-next-ssr","owner":"correttojs","description":"Autogenerate apollo code for nextjs ssr","archived":false,"fork":false,"pushed_at":"2025-05-14T19:36:02.000Z","size":6005,"stargazers_count":199,"open_issues_count":30,"forks_count":36,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-14T20:43:07.044Z","etag":null,"topics":["apollo-client","codegen","graphql","graphql-code-generator","graphql-codegen","nextjs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/correttojs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2020-06-20T15:04:21.000Z","updated_at":"2025-04-01T15:25:57.000Z","dependencies_parsed_at":"2024-05-17T21:28:34.106Z","dependency_job_id":"6b097576-0583-42c4-b258-20a6213ac9ab","html_url":"https://github.com/correttojs/graphql-codegen-apollo-next-ssr","commit_stats":{"total_commits":657,"total_committers":16,"mean_commits":41.0625,"dds":0.634703196347032,"last_synced_commit":"1e3b57d64ea251f2665a5a499ff2c51f425e736f"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/correttojs%2Fgraphql-codegen-apollo-next-ssr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/correttojs%2Fgraphql-codegen-apollo-next-ssr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/correttojs%2Fgraphql-codegen-apollo-next-ssr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/correttojs%2Fgraphql-codegen-apollo-next-ssr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/correttojs","download_url":"https://codeload.github.com/correttojs/graphql-codegen-apollo-next-ssr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319718,"owners_count":22051072,"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":["apollo-client","codegen","graphql","graphql-code-generator","graphql-codegen","nextjs"],"created_at":"2024-08-03T01:03:36.458Z","updated_at":"2025-05-15T10:05:38.955Z","avatar_url":"https://github.com/correttojs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# ⚠ Maintaner needed ⚠\n \nAn alternative solution based on `swr` and `gql-request` can be found [here](https://github.com/correttojs/swr-gql)\n\n\n# graphql-codegen-apollo-next-ssr\nGenerate apollo code for nextjs ssr\n\n\n## Motivations\n\nNextjs recently introduced `getServerSideProps` which doesn't allow to use the HOC pattern adopted by the official apollo graphql plugin (based on `getInitialProps`). At the same time the SSR method offered by apollo client (`getDataFromTree` ) enforces the react app to render multiple times in order to collect and fetch all the relevant queries.\nBy declaring a top level query we can save rendering time and provide a simpler pattern which works with `getServerSideProps `. This plugin generates a typesafe version of `getServerSideProps ` for each server query, and the corresponding HOC to wrap the react component returning the cache result. The limitation/advantage of this solution is that all the queries embedded into inner react components are ignored, unless covered by the top level cache.\n\n## Configuration\n- `excludePatterns` (default: null): regexp to exclude operation names\n- `excludePatternsOptions` (default: ''): regexp flags to exclude operation names\n- `reactApolloVersion` (default: 2): apollo client version\n- `apolloCacheImportFrom` (default: apollo-cache-inmemory): apollo-cache-inmemory dependency\n- `apolloImportFrom` (default: apollo-client v2 or @apollo/client v3): apollo client dependency\n- `apolloCacheImportFrom` (default: apollo-cache-inmemory v2 or @apollo/client v3): apollo cache client dependency\n- `apolloStateKey` (default: apolloState): Key used for storing Apollo state\n- `withHooks` (default: false): Customized the output by enabling/disabling the generated React Hooks.\n- `withHOC` (default: true):  Customized the output by enabling/disabling the HOC.\n- `customImports` (default: ''): full custom import declaration\n- `contextType` (default: 'any'): Contex type passed to getApolloClient\n- `contextTypeRequired` (default: false): If the context should be required when called from getServerSideProps\n- `pre` (default: ''): custom code before each function\n- `post` (default: ''):  custom code after each function\n- `apolloClientInstanceImport`(default: ''): Add apolloClient instance imports\n- `replaceQuery` (default: false): Replace \"query\" keyword inside the generated operations \n- `replacePage` (default: false): Replace \"page\" keyword inside the generated operations \n- `reactImport` (default: import type React from 'react';): custom react import \n\n## Example config\n\n```\noverwrite: true\nschema:\n    - 'https://myschema/graphql'\ndocuments:\n    - 'src/**/*.graphql'\ngenerates:\n    src/@types/codegen/graphql.tsx:\n        plugins:\n            - 'typescript'\n            - 'typescript-operations'\n            - 'typescript-react-apollo'\n    src/@types/codegen/page.tsx:\n        config:\n            documentMode: external\n            importDocumentNodeExternallyFrom: ./graphql\n        preset: import-types\n        presetConfig:\n            typesPath: ./graphql\n        plugins:\n            - ./build/src/index.js\nhooks:\n    afterAllFileWrite:\n        - prettier --write\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorrettojs%2Fgraphql-codegen-apollo-next-ssr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorrettojs%2Fgraphql-codegen-apollo-next-ssr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorrettojs%2Fgraphql-codegen-apollo-next-ssr/lists"}