Integrating websocket link results in constat logging in console
Opened this issue · 2 comments
1awaleed commented
I tried the first time to integrate WebSocketLink
and it worked like a charm but as soon as I added WebSocketLink
, the console keeps logging the same line every 1 minute. This is happening in a react-native
project in a development build.
Expected Behavior
No logging.
Actual Behavior
The line being logged:
SocketRocket: In debug mode. Allowing connection to any root cert
A simple reproduction
How to reproduce:
The problem is occurring in a react native project, So to reproduce
npx react-native init myApp
- Install all required dependencies used in the following piece of code.
- Create
apolloInit.js
.
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { setContext } from 'apollo-link-context'
import { split } from 'apollo-link'
import { WebSocketLink } from 'apollo-link-ws'
import { getMainDefinition } from 'apollo-utilities'
// Create an http link:
const httpLink = new HttpLink({
uri: 'https://localhost:3000/graphql'
});
const authLink = setContext((operation, { headers }) => {
// get the authentication token from storage if it exists
const token = await Asyncstorage.get('token')
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
},
}
})
// Create a WebSocket link:
const token = await Asyncstorage.get('token')
const wsLink = new WebSocketLink({
uri: `wss://localhost:5000/`,
options: {
reconnect: true,
connectionParams: { authorization: token ? `Bearer ${token}` : '' }
}
});
// using the ability to split links, you can send data to each link
// depending on what kind of operation is being sent
const link = split(
// split based on operation type
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
);
},
wsLink,
authLink.concat(httpLink),
);
- Modify
app.js
as follows:
import React from 'react'
import { View } from 'react-native'
import { ApolloProvider } from '@apollo/react-hooks'
import { store, persistor } from './src/redux/store/index'
import { client } from './src/services/apolloInitialization'
import { TestScreen } from './screens'
<ApolloProvider client={client}>
<View />
</ApolloProvider>
mauriciopf commented
@ 1awaleed hi, Im getting the same, were you able to fix this?
1awaleed commented
@mauriciopf No unfortunately. But the subscriptions using the websocket link is working fine. It is just spamming our debug console.