Ocelot-Social/webapp/plugins/apollo-config.js
roschaefer 2e19cf6592 fix(nuxt-env): Configuration issue with websockets
After some intensive debugging I found out that `req` (on the server)
and `nuxtState` (on the client) have access to the configurations
changed at runtime.

How did I debug it:
```
yarn run build
env WEBSOCKET_URI=whatever yarn run start
```
I also put a `console.log` into `plugins/apollo-client.js`.
2020-02-17 23:30:50 +01:00

25 lines
770 B
JavaScript

import { InMemoryCache, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory'
import introspectionQueryResultData from './apollo-config/fragmentTypes.json'
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData,
})
export default ({ req, nuxtState }) => {
const { env } = req || nuxtState
const backendUrl = env.GRAPHQL_URI || 'http://localhost:4000'
return {
wsEndpoint: env.WEBSOCKETS_URI || 'ws://localhost:4000/graphql',
httpEndpoint: process.server ? backendUrl : '/api',
httpLinkOptions: {
credentials: 'same-origin',
},
credentials: true,
tokenName: 'human-connection-token',
persisting: false,
websocketsOnly: false,
cache: new InMemoryCache({ fragmentMatcher }),
}
}