adamsoffer/next-apollo
关于
用于将 Apollo Client 集成到 Next.js 的 React 高阶组件
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Next Apollo 
A package for using Apollo within a Next.js application.
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) => <div>Hello World</div>;
// 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
探索相关项目
加载中…