Created
March 16, 2018 06:43
-
-
Save davidroyer/5c22b625d4638c49c46606eb1b4f536c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// import { HttpLink } from 'apollo-link-http' | |
// import { InMemoryCache } from 'apollo-cache-inmemory' | |
import { ApolloLink } from 'apollo-link' | |
import { HttpLink } from 'apollo-link-http' | |
import { InMemoryCache } from 'apollo-cache-inmemory' | |
const GRAPHCMS_API = 'https://api.graphcms.com/simple/v1/myBlog' | |
export default (ctx) => { | |
const httpLink = new HttpLink({ uri: GRAPHCMS_API }) | |
// middleware | |
const middlewareLink = new ApolloLink((operation, forward) => { | |
const token = process.server ? ctx.req.session : window.__NUXT__.state.session | |
operation.setContext({ | |
headers: { authorization: `Bearer ${token}` } | |
}) | |
return forward(operation) | |
}) | |
const link = middlewareLink.concat(httpLink) | |
return { | |
link, | |
cache: new InMemoryCache() | |
} | |
} | |
// Replace this with your project's endpoint | |
// const GRAPHCMS_API = 'https://api.graphcms.com/simple/v1/myBlog' | |
// | |
// export default () => ({ | |
// link: new HttpLink({ uri: GRAPHCMS_API }), | |
// cache: new InMemoryCache() | |
// }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment