The Idea Behind This Example
9 |10 | Apollo is a GraphQL client that 11 | allows you to easily query the exact data you need from a GraphQL 12 | server. In addition to fetching and mutating data, Apollo analyzes your 13 | queries and their results to construct a client-side cache of your data, 14 | which is kept up to date as further queries and mutations are run, 15 | fetching more results from the server. 16 |
17 |18 | In this simple example, we integrate Apollo seamlessly with{' '} 19 | Next by wrapping our pages 20 | inside a{' '} 21 | 22 | higher-order component (HOC) 23 | . Using the HOC pattern we're able to pass down a central store of 24 | query result data created by Apollo into our React component hierarchy 25 | defined inside each page of our Next application. 26 |
27 |28 | On initial page load, while on the server and inside getInitialProps, we 29 | invoke the Apollo method,{' '} 30 | 31 | getDataFromTree 32 | . This method returns a promise; at the point in which the promise 33 | resolves, our Apollo Client store is completely initialized. 34 |
35 |36 | This example relies on graph.cool for 37 | its GraphQL backend. 38 |
39 |