// 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()
// })