-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make withApollo work with _app.js components * Support wrapping functional _App * Add apolloClient to NextPageContext & NextPageContext * Propertly call App.getInitialProps if used in NextAppContext * Add Automatic Static Optimization warning * Update deps * Reduce API surface * Move back to singleton client * Improve documentation * Remove Head.rewind() We can get rid of .rewind by now as the latest next/head no longer uses legacy context. * Add extra docs * Reuse apolloState coming from previous hocs Co-authored-by: Joe Haddad <[email protected]>
- Loading branch information
Showing
6 changed files
with
128 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ApolloClient } from 'apollo-client' | ||
import { InMemoryCache } from 'apollo-cache-inmemory' | ||
import { HttpLink } from 'apollo-link-http' | ||
import fetch from 'isomorphic-unfetch' | ||
|
||
export default function createApolloClient(initialState, ctx) { | ||
// The `ctx` (NextPageContext) will only be present on the server. | ||
// use it to extract auth headers (ctx.req) or similar. | ||
return new ApolloClient({ | ||
ssrMode: Boolean(ctx), | ||
link: new HttpLink({ | ||
uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn', // Server URL (must be absolute) | ||
credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers` | ||
fetch, | ||
}), | ||
cache: new InMemoryCache().restore(initialState), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters