Created
March 27, 2019 00:46
-
-
Save homerquan/4237d861c80d1c8afd7147bdfa87ef0d to your computer and use it in GitHub Desktop.
apollo client with graphql-subscription 1.x to 2.x
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
const uri = 'https://api.graph.cool/simple/v1/cj7yuh1df1tnt0147ihz25bgi' | |
const wsClient = { | |
uri: 'wss://subscriptions.graph.cool/v1/cj7yuh1df1tnt0147ihz25bgi', | |
options: { | |
reconnect: true, | |
connectionParams: { | |
authToken: localStorage.getItem(GC_AUTH_TOKEN), | |
} | |
} | |
} | |
const link = ApolloLink.split( | |
operation => { // check if it is a subscription | |
const operationAST = getOperationAST(operation.query, operation.operationName); | |
return !!operationAST && operationAST.operation === 'subscription'; | |
}, | |
new WebSocketLink(wsClient), | |
new HttpLink({ uri }), | |
); | |
const client = new ApolloClient({ | |
networkInterface: link | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment