Skip to content

Commit b30fb27

Browse files
author
Guillaume Chau
committed
docs: fix migration guide
1 parent f1a1e8b commit b30fb27

File tree

1 file changed

+84
-73
lines changed

1 file changed

+84
-73
lines changed

README.md

Lines changed: 84 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,72 @@ import { InMemoryCache } from 'apollo-cache-inmemory'
17471747
import VueApollo from 'vue-apollo'
17481748
```
17491749

1750+
#### Apollo Setup
1751+
1752+
Before:
1753+
1754+
```js
1755+
// Create the network interface
1756+
const networkInterface = createNetworkInterface({
1757+
uri: 'http://localhost:3000/graphql',
1758+
transportBatching: true,
1759+
})
1760+
1761+
// Create the subscription websocket client
1762+
const wsClient = new SubscriptionClient('ws://localhost:3000/subscriptions', {
1763+
reconnect: true,
1764+
})
1765+
1766+
// Extend the network interface with the subscription client
1767+
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
1768+
networkInterface,
1769+
wsClient,
1770+
)
1771+
1772+
// Create the apollo client with the new network interface
1773+
const apolloClient = new ApolloClient({
1774+
networkInterface: networkInterfaceWithSubscriptions,
1775+
connectToDevTools: true,
1776+
})
1777+
```
1778+
1779+
After:
1780+
1781+
```js
1782+
const httpLink = new HttpLink({
1783+
// You should use an absolute URL here
1784+
uri: 'http://localhost:3020/graphql',
1785+
})
1786+
1787+
// Create the subscription websocket link
1788+
const wsLink = new WebSocketLink({
1789+
uri: 'ws://localhost:3000/subscriptions',
1790+
options: {
1791+
reconnect: true,
1792+
},
1793+
})
1794+
1795+
// using the ability to split links, you can send data to each link
1796+
// depending on what kind of operation is being sent
1797+
const link = split(
1798+
// split based on operation type
1799+
({ query }) => {
1800+
const { kind, operation } = getMainDefinition(query)
1801+
return kind === 'OperationDefinition' &&
1802+
operation === 'subscription'
1803+
},
1804+
wsLink,
1805+
httpLink
1806+
)
1807+
1808+
// Create the apollo client
1809+
const apolloClient = new ApolloClient({
1810+
link,
1811+
cache: new InMemoryCache(),
1812+
connectToDevTools: true,
1813+
})
1814+
```
1815+
17501816
#### Plugin Setup
17511817

17521818
Before:
@@ -1761,7 +1827,13 @@ const apolloClient = new ApolloClient({
17611827
})
17621828

17631829
// Install the vue plugin
1764-
Vue.use(VueApollo)
1830+
Vue.use(VueApollo, {
1831+
apolloClient,
1832+
})
1833+
1834+
new Vue({
1835+
// ...
1836+
})
17651837
```
17661838

17671839
After:
@@ -1781,6 +1853,17 @@ const apolloClient = new ApolloClient({
17811853

17821854
// Install the vue plugin
17831855
Vue.use(VueApollo)
1856+
1857+
// Create a provider
1858+
const apolloProvider = new VueApollo({
1859+
defaultClient: apolloClient,
1860+
})
1861+
1862+
// Use the provider
1863+
new Vue({
1864+
provide: apolloProvider.provide(),
1865+
// ...
1866+
})
17841867
```
17851868

17861869
### Mutations
@@ -1819,78 +1902,6 @@ import { WebSocketLink } from 'apollo-link-ws'
18191902
import { getMainDefinition } from 'apollo-utilities'
18201903
```
18211904

1822-
#### Apollo Setup
1823-
1824-
Before:
1825-
1826-
```js
1827-
// Create the network interface
1828-
const networkInterface = createNetworkInterface({
1829-
uri: 'http://localhost:3000/graphql',
1830-
transportBatching: true,
1831-
})
1832-
1833-
// Create the subscription websocket client
1834-
const wsClient = new SubscriptionClient('ws://localhost:3000/subscriptions', {
1835-
reconnect: true,
1836-
})
1837-
1838-
// Extend the network interface with the subscription client
1839-
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
1840-
networkInterface,
1841-
wsClient,
1842-
)
1843-
1844-
// Create the apollo client with the new network interface
1845-
const apolloClient = new ApolloClient({
1846-
networkInterface: networkInterfaceWithSubscriptions,
1847-
connectToDevTools: true,
1848-
})
1849-
1850-
// Install the plugin like before
1851-
Vue.use(VueApollo)
1852-
```
1853-
1854-
After:
1855-
1856-
```js
1857-
const httpLink = new HttpLink({
1858-
// You should use an absolute URL here
1859-
uri: 'http://localhost:3020/graphql',
1860-
})
1861-
1862-
// Create the subscription websocket link
1863-
const wsLink = new WebSocketLink({
1864-
uri: 'ws://localhost:3000/subscriptions',
1865-
options: {
1866-
reconnect: true,
1867-
},
1868-
})
1869-
1870-
// using the ability to split links, you can send data to each link
1871-
// depending on what kind of operation is being sent
1872-
const link = split(
1873-
// split based on operation type
1874-
({ query }) => {
1875-
const { kind, operation } = getMainDefinition(query)
1876-
return kind === 'OperationDefinition' &&
1877-
operation === 'subscription'
1878-
},
1879-
wsLink,
1880-
httpLink
1881-
)
1882-
1883-
// Create the apollo client
1884-
const apolloClient = new ApolloClient({
1885-
link,
1886-
cache: new InMemoryCache(),
1887-
connectToDevTools: true,
1888-
})
1889-
1890-
// Install the vue plugin like before
1891-
Vue.use(VueApollo)
1892-
```
1893-
18941905

18951906
<br>
18961907

0 commit comments

Comments
 (0)