This file contains hidden or 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
export const connectWebSocket = <T>( | |
webSocketUrl: string, | |
pollingUrl: string = "", | |
updateFunc: (updateItem: T) => any, | |
registerError?: (errorId: string, err: any, cause?:any) => void, | |
__isReconnecting__: boolean = false, | |
__hasPrevConnection: boolean = false | |
): CleanUpFunction => { | |
const cleanUpFunctions: CleanUpFunction[] = []; | |
const fixedWebSocketUrl = convertToWebsocketUrl(webSocketUrl); |
This file contains hidden or 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
/*** | |
* Problems with previous solution | |
* | |
* 1. No fallback UI was provided | |
2. You don't need to wrap all individual component in a separate suspense. | |
3. The component to be suspended must throw a promise if requisite data is not available | |
*/ | |
import * as React from "react"; |
This file contains hidden or 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 { InMemoryCache } from "apollo-cache-inmemory"; | |
import { createHttpLink } from "apollo-link-http"; | |
import { WebSocketLink } from "apollo-link-ws"; | |
import { ApolloClient } from "apollo-client"; | |
import { split } from "apollo-link"; | |
import { getMainDefinition } from "apollo-utilities"; | |
const httpLink = createHttpLink({ uri: "http://localhost:8080/" }); | |
const wsLink = new WebSocketLink({ | |
uri: `ws://localhost:8080/graphql`, |