MCPcopy Index your code
hub / github.com/adamsoffer/next-apollo

github.com/adamsoffer/next-apollo @5.0.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release 5.0.8 ↗ · + Follow
5 symbols 16 edges 3 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Next Apollo Build Status

A package for using Apollo within a Next.js application.

Demo

Installation

This project assumes you have react, react-dom, and next installed. They're specified as peerDependencies.

npm install --save next-apollo graphql @apollo/client

Documentation

Create an Apollo Client, pass it into to the withApollo higher-order component and export the returned component.

import { withApollo } from "next-apollo";
import { ApolloClient, InMemoryCache } from "@apollo/client";

const apolloClient = new ApolloClient({
  uri: "https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn",
  cache: new InMemoryCache(),
});

export default withApollo(apolloClient);

Inside your Next.js page, wrap your component with your exported higher order component.

import withApollo from "../lib/apollo";

const Page = (props) => 

Hello World

;

// Default export is required for Fast Refresh
export default withApollo({ ssr: true })(Page);

That's it!

How Does It Work?

Next-apollo integrates Apollo seamlessly with Next by wrapping our pages inside a higher-order component (HOC). Using a HOC pattern we're able to pass down a central store of query result data created by Apollo into our React component hierarchy defined inside each page of our Next application.

On initial page load, while on the server and inside getInitialProps, the Apollo method, getDataFromTree, is invoked and returns a promise; at the point in which the promise resolves, our Apollo Client store is completely initialized.

License

MIT

Core symbols most depended-on inside this repo

initApolloClient
called by 2
src/withApollo.tsx
createApolloClient
called by 2
src/withApollo.tsx
initOnContext
called by 1
src/withApollo.tsx
withApollo
called by 0
src/withApollo.tsx
WithApollo
called by 0
src/withApollo.tsx

Shape

Function 5

Languages

TypeScript100%

Modules by API surface

src/withApollo.tsx5 symbols

For agents

$ claude mcp add next-apollo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page