Skip to content

Commit d64c1a0

Browse files
author
Guillaume Chau
committed
refactor(ui): use only web sockets
1 parent 3c4f206 commit d64c1a0

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

packages/@vue/cli-ui/src/apollo.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,31 @@
11
import { ApolloClient } from 'apollo-client'
2-
import { split, ApolloLink } from 'apollo-link'
3-
import { HttpLink } from 'apollo-link-http'
2+
import { ApolloLink } from 'apollo-link'
43
import { InMemoryCache } from 'apollo-cache-inmemory'
54
import { SubscriptionClient } from 'subscriptions-transport-ws'
65
import { WebSocketLink } from 'apollo-link-ws'
7-
import { getMainDefinition } from 'apollo-utilities'
86
import { withClientState } from 'apollo-link-state'
97
import defaults from './state/defaults'
108
import resolvers from './state/resolvers'
119

1210
// Create the apollo client
1311
export default function createApolloClient ({ base, endpoints, persisting }) {
14-
let link
15-
let wsClient
16-
17-
let httpLink = new HttpLink({
18-
// You should use an absolute URL here
19-
uri: base + endpoints.graphql
20-
})
21-
2212
// Apollo cache
2313
const cache = new InMemoryCache()
2414

2515
// Client-side state
2616
const stateLink = withClientState({ defaults, cache, resolvers })
2717

2818
// Web socket
29-
wsClient = new SubscriptionClient(base.replace(/^https?/i, 'ws') +
19+
const wsClient = new SubscriptionClient(base.replace(/^https?/i, 'ws') +
3020
endpoints.subscription, {
3121
reconnect: true
3222
})
3323

3424
// Create the subscription websocket link
3525
const wsLink = new WebSocketLink(wsClient)
3626

37-
link = split(
38-
// split based on operation type
39-
({ query }) => {
40-
const { kind, operation } = getMainDefinition(query)
41-
return kind === 'OperationDefinition' &&
42-
operation === 'subscription'
43-
},
44-
wsLink,
45-
httpLink
46-
)
47-
4827
const apolloClient = new ApolloClient({
49-
link: ApolloLink.from([stateLink, link]),
28+
link: ApolloLink.from([stateLink, wsLink]),
5029
cache
5130
})
5231

0 commit comments

Comments
 (0)