{"id":16186166,"url":"https://github.com/zenflow/next-ssr-with-apollo","last_synced_at":"2025-07-16T07:41:40.398Z","repository":{"id":63133151,"uuid":"553888627","full_name":"zenflow/next-ssr-with-apollo","owner":"zenflow","description":"Opinionated HOC to integrate Apollo into an SSR Next.js app","archived":false,"fork":false,"pushed_at":"2022-11-14T01:39:13.000Z","size":329,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T05:05:10.458Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/zenflow.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}},"created_at":"2022-10-18T23:44:16.000Z","updated_at":"2024-02-10T03:16:04.000Z","dependencies_parsed_at":"2023-01-21T16:45:14.650Z","dependency_job_id":null,"html_url":"https://github.com/zenflow/next-ssr-with-apollo","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/zenflow/next-ssr-with-apollo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fnext-ssr-with-apollo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fnext-ssr-with-apollo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fnext-ssr-with-apollo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fnext-ssr-with-apollo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zenflow","download_url":"https://codeload.github.com/zenflow/next-ssr-with-apollo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fnext-ssr-with-apollo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265492958,"owners_count":23776149,"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":"2024-10-10T07:17:19.297Z","updated_at":"2025-07-16T07:41:40.050Z","avatar_url":"https://github.com/zenflow.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# next-ssr-with-apollo\nOpinionated HOC to integrate Apollo into an SSR Next.js app\n\n[![npm version](https://img.shields.io/npm/v/next-ssr-with-apollo)](http://npmjs.com/package/next-ssr-with-apollo)\n[![Known Vulnerabilities](https://snyk.io/test/github/zenflow/next-ssr-with-apollo/badge.svg?targetFile=package.json)](https://snyk.io/test/github/zenflow/next-ssr-with-apollo?targetFile=package.json)\n[![GitHub issues welcome](https://img.shields.io/badge/issues-welcome-brightgreen.svg?logo=GitHub)](https://github.com/zenflow/next-ssr-with-apollo/issues)\n[![GitHub pull requests welcome](https://img.shields.io/badge/pull%20requests-welcome-brightgreen.svg?logo=GitHub)](https://github.com/zenflow/next-ssr-with-apollo/pulls)\n[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- Allow child components to declare their own data dependencies.\n*(None of the prop-drilling from getServerSideProps examples.)*\n- Support data dependencies in any component, including components used in App layout.\n*(Note this uses App getInitialProps and opts-out of any pages in the app being static.)*\n- Prefetch data before displaying new route on client-side navigation, same as server-side navigation.\n*(Avoid displaying next page in a loading state.)*\n- Simplified caching model: Start fresh when navigating to new route.\n*(Don't worry about so much about `fetchPolicy`, `nextFetchPolicy`, manually refetching queries,\nor the [unpredictabile side-effects of these features](https://github.com/apollographql/apollo-client/issues/7938).*\n\n## Installation\n\nInside your Next.js project:\n\n```\nnpm install graphql @apollo/client next-ssr-with-apollo\n```\n\n## Usage\n\nWrap your App component to provide apollo client for your entire app.\n\npages/App.tsx\n\n```tsx\nimport type { AppProps } from \"next/app\";\nimport { ApolloClient, InMemoryCache } from \"@apollo/client\";\nimport { createWithApollo } from \"next-ssr-with-apollo\";\n\nconst withApollo = createWithApollo({\n  client() {\n    return new ApolloClient({\n      uri: \"https://rickandmortyapi.graphcdn.app/\",\n      cache: new InMemoryCache(),\n    });\n  },\n});\n\nfunction MyApp({ Component, pageProps }: AppProps) {\n  return \u003cComponent {...pageProps} /\u003e;\n}\n\nexport default withApollo(MyApp);\n```\n\nNow you can use [apollo hooks](https://www.apollographql.com/docs/react/api/react/hooks/#usequery)\nin any component in your app, and queries will be prefetched before a route is shown.\n\nQueries with the `ssr: false` option won't be prefetched (server-side *or client-side*).\nThey will initially be in a loading state when the route is shown.\n\n## Options\n\n### `client`\n\nThe `client` factory, where you define your Apollo Client, is invoked:\n- on server: once per request\n- on client: once per page load *and once per client-side navigation*\n\nThe `client` factory receives some params:\n- `headers` - HTTP request headers. Only defined on server side.\n\n**Example**\n\n```tsx\nconst withApollo = createWithApollo({\n  client({ headers }) {\n    const isServer = typeof window === \"undefined\";\n    const baseUri = isServer ? \"http://127.0.0.1:3000\" : \"\";\n    return new ApolloClient({\n      uri: `${baseUri}/api/graphql`,\n      headers:\n        isServer \u0026\u0026 headers!.authorization\n          ? { authorization: headers!.authorization }\n          : {},\n      cache: new InMemoryCache(),\n    });\n  },\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenflow%2Fnext-ssr-with-apollo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzenflow%2Fnext-ssr-with-apollo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenflow%2Fnext-ssr-with-apollo/lists"}