Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Integrating websocket link results in constat logging in console #1286

Open
1awaleed opened this issue Jun 19, 2020 · 2 comments
Open

Integrating websocket link results in constat logging in console #1286

1awaleed opened this issue Jun 19, 2020 · 2 comments

Comments

@1awaleed
Copy link

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

  1. npx react-native init myApp
  2. Install all required dependencies used in the following piece of code.
  3. 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),
);
  1. 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
Copy link

@ 1awaleed hi, Im getting the same, were you able to fix this?

@1awaleed
Copy link
Author

1awaleed commented Jul 3, 2020

@mauriciopf No unfortunately. But the subscriptions using the websocket link is working fine. It is just spamming our debug console.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants