Created
January 16, 2020 03:24
-
-
Save juddey/23aec776471c0b8efad47be48894d49d to your computer and use it in GitHub Desktop.
Ws Connection Issue
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
Setup in my ApolloStartup file | |
import wsLink from './wsLink' | |
// wsLink.js | |
import WSLink from './Link' | |
import Config from 'react-native-config' | |
export default () => new WSLink(Config.REACT_APP_WS_URL) |
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
import * as AbsintheSocket from '@absinthe/socket' | |
import { createAbsintheSocketLink } from '@absinthe/socket-apollo-link' | |
import { ApolloLink } from 'apollo-link' | |
import { Socket } from 'phoenix' | |
import { fetchAuth } from '~/services/Keychain' | |
export default class WebSocketLink extends ApolloLink { | |
token = null | |
constructor (url) { | |
super() | |
this.url = url | |
} | |
updateLink (token) { | |
this.token = token | |
this.link = createAbsintheSocketLink( | |
AbsintheSocket.create(new Socket(this.url, { params: { token: this.token } })) | |
) | |
} | |
request (operation, forward) { | |
const token = operation.getContext().headers.authorization | |
if (!this.link || token !== this.token) this.updateLink(token) | |
return this.link.request(operation, forward) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment