Skip to content

Commit 044acf1

Browse files
committed
feat: strict tsconfig and @apollo/client v3
1 parent 01d1647 commit 044acf1

35 files changed

+415
-414
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ A clear and concise description of what you expected to happen.
2323
**Versions**
2424
vue:
2525
vue-apollo:
26-
apollo-client:
26+
@apollo/client:
2727

2828
**Additional context**
2929
Add any other context about the problem here.

packages/docs/src/guide-advanced/ssr.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ Here is an example:
137137
// apollo.js
138138
139139
import Vue from 'vue'
140-
import { ApolloClient } from 'apollo-client'
141-
import { HttpLink } from 'apollo-link-http'
142-
import { InMemoryCache } from 'apollo-cache-inmemory'
140+
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client/core'
143141
import VueApollo from '@vue/apollo-option'
144142
145143
// Install the vue plugin

packages/docs/src/guide-composable/error-handling.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export default {
5555

5656
## Network Errors
5757

58-
When using Apollo Link, the ability to handle network errors is way more powerful. The best way to do this is to use the `apollo-link-error` to catch and handle server errors, network errors, and GraphQL errors. If you would like to combine with other links, see [composing links](https://www.apollographql.com/docs/link/composition).
58+
When using Apollo Link, the ability to handle network errors is way more powerful. The best way to do this is to use the `@apollo/client/link/error` to catch and handle server errors, network errors, and GraphQL errors. If you would like to combine with other links, see [composing links](https://www.apollographql.com/docs/link/composition).
5959

6060
```js
61-
import { onError } from 'apollo-link-error'
61+
import { onError } from '@apollo/client/link/error'
6262

6363
const link = onError(({ graphQLErrors, networkError }) => {
6464
if (graphQLErrors)
@@ -75,7 +75,7 @@ const link = onError(({ graphQLErrors, networkError }) => {
7575
You can also use the `logErrorMessages` function from the `@vue/apollo-util` package to format the error in the browser console:
7676

7777
```js
78-
import { onError } from 'apollo-link-error'
78+
import { onError } from '@apollo/client/link/error'
7979
import { logErrorMessages } from '@vue/apollo-util'
8080

8181
const link = onError(error => {
@@ -90,7 +90,7 @@ Example error:
9090
If you are using Webpack or Vue CLI, it's a good idea to only use it in development:
9191

9292
```js
93-
import { onError } from 'apollo-link-error'
93+
import { onError } from '@apollo/client/link/error'
9494
import { logErrorMessages } from '@vue/apollo-util'
9595

9696
const link = onError(error => {
@@ -121,4 +121,4 @@ onError(({ response, operation }) => {
121121
response.errors = null
122122
}
123123
})
124-
```
124+
```

packages/docs/src/guide-composable/fragments.md

+9-87
Original file line numberDiff line numberDiff line change
@@ -203,105 +203,27 @@ query {
203203
}
204204
```
205205

206-
In the query above, `allPeople` returns a result of type `Character[]`. Both `Jedi` and `Droid` are possible concrete types of `Character`, but on the client there is no way to know that without having some information about the schema. By default, Apollo Client's cache will use a heuristic fragment matcher, which assumes that a fragment matched if the result included all the fields in its selection set, and didn't match when any field was missing. This works in most cases, but it also means that Apollo Client cannot check the server response for you, and it cannot tell you when you're manually writing invalid data into the store using `update`, `updateQuery`, `writeQuery`, etc. Also, the heuristic fragment matcher will not work accurately when using fragments with unions or interfaces. Apollo Client will let you know this with a console warning (in development), if it attempts to use the default heuristic fragment matcher with unions/interfaces. The `IntrospectionFragmentMatcher` is the solution for working with unions/interfaces, and is explained in more detail below.
206+
In the query above, `allPeople` returns a result of type `Character[]`. Both `Jedi` and `Droid` are possible concrete types of `Character`, but on the client there is no way to know that without having some information about the schema. By default, Apollo Client's cache will use a heuristic fragment matcher, which assumes that a fragment matched if the result included all the fields in its selection set, and didn't match when any field was missing. This works in most cases, but it also means that Apollo Client cannot check the server response for you, and it cannot tell you when you're manually writing invalid data into the store using `update`, `updateQuery`, `writeQuery`, etc. To inform the cache store about these polymorphic relationships, you need to pass `possibleTypes` option to `InMemoryCache` below.
207207

208208
The section below explains how to pass the necessary schema knowledge to the Apollo Client cache so unions and interfaces can be accurately matched and results validated before writing them into the store.
209209

210-
To support result validation and accurate fragment matching on unions and interfaces, a special fragment matcher called the `IntrospectionFragmentMatcher` can be used. If there are any changes related to union or interface types in your schema, you will have to update the fragment matcher accordingly.
211-
212-
We recommend setting up a build step that extracts the necessary information from the schema into a JSON file, where it can be imported from when constructing the fragment matcher. To set it up, follow the three steps below:
210+
We recommend setting up a build step that extracts the necessary information from the schema into a JSON file, where it can be imported from when constructing the cache. To set it up, follow the steps below:
213211

214212
1. Query your server / schema to obtain the necessary information about unions and interfaces and write it to a file.
215213

216-
You can automate this or set this as a script to run at build time.
217-
218-
If you want to auto-generate the introspection result, there's a tool called [GraphQL Code Generator](https://graphql-code-generator.com) that does it. Define where your GraphQL Schema is available and where to write the file:
219-
220-
```yaml
221-
# codegen.yml
222-
schema: YOUR_API
223-
overwrite: true
224-
generates:
225-
./fragmentTypes.json:
226-
plugins:
227-
- fragment-matcher
228-
```
229-
230-
With all of that, you simply run:
231-
232-
```shell
233-
gql-gen
234-
```
235-
236-
> To learn more, you can read the ["Fragment Matcher" chapter](https://graphql-code-generator.com/docs/plugins/fragment-matcher).
237-
238-
In order to introspect the server manually, set this as a script to run at build time.
239-
240-
```js
241-
const fetch = require('node-fetch')
242-
const fs = require('fs')
243-
244-
fetch(`${YOUR_API_HOST}/graphql`, {
245-
method: 'POST',
246-
headers: { 'Content-Type': 'application/json' },
247-
body: JSON.stringify({
248-
variables: {},
249-
query: `
250-
{
251-
__schema {
252-
types {
253-
kind
254-
name
255-
possibleTypes {
256-
name
257-
}
258-
}
259-
}
260-
}
261-
`,
262-
}),
263-
})
264-
.then(result => result.json())
265-
.then(result => {
266-
// here we're filtering out any type information unrelated to unions or interfaces
267-
const filteredData = result.data.__schema.types.filter(
268-
type => type.possibleTypes !== null,
269-
)
270-
result.data.__schema.types = filteredData
271-
fs.writeFile('./fragmentTypes.json', JSON.stringify(result.data), err => {
272-
if (err) {
273-
console.error('Error writing fragmentTypes file', err)
274-
} else {
275-
console.log('Fragment types successfully extracted!')
276-
}
277-
})
278-
})
279-
```
280-
281-
2. Create a new IntrospectionFragment matcher by passing in the `fragmentTypes.json` file you just created. You'll want to do this in the same file where you initialize the cache for Apollo Client.
214+
Read the documentation about how to [extract possibleTypes automatically](https://www.apollographql.com/docs/react/data/fragments/#generating-possibletypes-automatically) using an introspection query. Or use the plugin [fragment-matcher](https://graphql-code-generator.com/docs/plugins/fragment-matcher) for graphql-codegen and configure it for [apollo client 3](https://graphql-code-generator.com/docs/plugins/fragment-matcher#usage-with-apollo-client-3).
282215

283-
```js
284-
import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory'
285-
import introspectionQueryResultData from './fragmentTypes.json'
286-
287-
const fragmentMatcher = new IntrospectionFragmentMatcher({
288-
introspectionQueryResultData
289-
})
290-
```
291-
292-
3. Pass in the newly created `IntrospectionFragmentMatcher` to configure your cache during construction. Then, you pass your newly configured cache to `ApolloClient` to complete the process.
216+
2. Use `possibleTypes.json` to configure your cache during construction. Then, you pass your newly configured cache to `ApolloClient` to complete the process.
293217

294218
```js
295-
import ApolloClient from 'apollo-client'
296-
import { InMemoryCache } from 'apollo-cache-inmemory'
297-
import { HttpLink } from 'apollo-link-http'
298-
299-
// add fragmentMatcher code from step 2 here
219+
import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client/core'
220+
import possibleTypes from './possibleTypes.json'
300221

301-
const cache = new InMemoryCache({ fragmentMatcher })
222+
const cache = new InMemoryCache({ possibleTypes })
223+
const httpLink = createHttpLink({ uri });
302224

303225
const client = new ApolloClient({
304226
cache,
305-
link: new HttpLink(),
227+
link: httpLink,
306228
})
307229
```

packages/docs/src/guide-composable/subscription.md

+7-20
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,14 @@ A future version of Apollo or GraphQL might include support for live queries, wh
5353

5454
## Client setup
5555

56-
The most popular transport for GraphQL subscriptions today is [`subscriptions-transport-ws`](https://github.com/apollographql/subscriptions-transport-ws). This package is maintained by the Apollo community, but can be used with any client or server GraphQL implementation. In this article, we'll explain how to set it up on the client, but you'll also need a server implementation. You can [read about how to use subscriptions with a JavaScript server](https://www.apollographql.com/docs/graphql-subscriptions/setup), or enjoy subscriptions set up out of the box if you are using a GraphQL backend as a service like [Graphcool](https://www.graph.cool/docs/tutorials/worldchat-subscriptions-example-ui0eizishe/).
56+
In this article, we'll explain how to set it up on the client, but you'll also need a server implementation. You can [read about how to use subscriptions with a JavaScript server](https://www.apollographql.com/docs/graphql-subscriptions/setup), or enjoy subscriptions set up out of the box if you are using a GraphQL backend as a service like [Graphcool](https://www.graph.cool/docs/tutorials/worldchat-subscriptions-example-ui0eizishe/).
5757

5858
Let's look at how to add support for this transport to Apollo Client.
5959

60-
First, install the WebSocket Apollo Link (`apollo-link-ws`) from npm:
61-
62-
```shell
63-
npm install --save apollo-link-ws subscriptions-transport-ws
64-
```
65-
66-
Or:
67-
68-
```shell
69-
yarn add apollo-link-ws subscriptions-transport-ws
70-
```
71-
72-
Then, initialize a GraphQL subscriptions transport link:
60+
First, initialize a GraphQL web socket link:
7361

7462
```js
75-
import { WebSocketLink } from "apollo-link-ws";
63+
import { WebSocketLink } from "@apollo/client/link/ws";
7664

7765
const wsLink = new WebSocketLink({
7866
uri: `ws://localhost:5000/`,
@@ -85,10 +73,9 @@ const wsLink = new WebSocketLink({
8573
We need to either use the `WebSocketLink` or the `HttpLink` depending on the operation type:
8674

8775
```js
88-
import { split } from "apollo-link";
89-
import { HttpLink } from "apollo-link-http";
90-
import { WebSocketLink } from "apollo-link-ws";
91-
import { getMainDefinition } from "apollo-utilities";
76+
import { HttpLink, split } from "@apollo/client/core";
77+
import { WebSocketLink } from "@apollo/client/link/ws";
78+
import { getMainDefinition } from "@apollo/client/utilities";
9279

9380
// Create an http link:
9481
const httpLink = new HttpLink({
@@ -569,7 +556,7 @@ subscribeToMore(() => ({
569556
In many cases it is necessary to authenticate clients before allowing them to receive subscription results. To do this, the `SubscriptionClient` constructor accepts a `connectionParams` field, which passes a custom object that the server can use to validate the connection before setting up any subscriptions.
570557

571558
```js
572-
import { WebSocketLink } from 'apollo-link-ws';
559+
import { WebSocketLink } from "@apollo/client/link/ws";
573560

574561
const wsLink = new WebSocketLink({
575562
uri: `ws://localhost:5000/`,

packages/docs/src/guide-option/subscriptions.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,11 @@
44

55
*For the server implementation, you can take a look at [this simple example](https://github.com/Akryum/apollo-server-example).*
66

7-
To enable the websocket-based subscription, a bit of additional setup is required:
8-
9-
```
10-
npm install --save apollo-link-ws apollo-utilities
11-
```
12-
137
```js
148
import Vue from 'vue'
15-
import { ApolloClient } from 'apollo-client'
16-
import { HttpLink } from 'apollo-link-http'
17-
import { InMemoryCache } from 'apollo-cache-inmemory'
18-
// New Imports
19-
import { split } from 'apollo-link'
20-
import { WebSocketLink } from 'apollo-link-ws'
21-
import { getMainDefinition } from 'apollo-utilities'
9+
import { ApolloClient, HttpLink, InMemoryCache, split } from '@apollo/client/core'
10+
import { WebSocketLink } from '@apollo/client/link/ws'
11+
import { getMainDefinition } from '@apollo/client/utilities'
2212

2313
import VueApollo from '@vue/apollo-option'
2414

packages/docs/src/guide/installation.md

+3-38
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,20 @@ Then you can skip to next section: [Basic Usage](./apollo/).
1616

1717
## Manual installation
1818

19-
You can either use [Apollo Boost](#apollo-boost) or [Apollo Client directly](#apollo-client-full-configuration) (more configuration work).
20-
21-
### Apollo Boost
22-
23-
Apollo Boost is a zero-config way to start using Apollo Client. It includes some sensible defaults, such as our recommended `InMemoryCache` and `HttpLink`, which come configured for you with our recommended settings and it's perfect for starting to develop fast.
24-
25-
Install it alongside `vue-apollo` and `graphql`:
26-
27-
```shell
28-
npm install --save graphql apollo-boost
29-
```
30-
31-
Or:
32-
33-
```shell
34-
yarn add graphql apollo-boost
35-
```
36-
37-
In your app, create an `ApolloClient` instance:
38-
39-
```js
40-
import ApolloClient from 'apollo-boost'
41-
42-
const apolloClient = new ApolloClient({
43-
// You should use an absolute URL here
44-
uri: 'https://api.graphcms.com/simple/v1/awesomeTalksClone'
45-
})
46-
```
47-
48-
### Apollo client full configuration
49-
50-
If you want some more fine grained control install these packages instead of apollo-boost:
51-
5219
```shell
53-
npm install --save graphql apollo-client apollo-link apollo-link-http apollo-cache-inmemory graphql-tag
20+
npm install --save graphql graphql-tag @apollo/client
5421
```
5522

5623
Or:
5724

5825
```shell
59-
yarn add graphql apollo-client apollo-link apollo-link-http apollo-cache-inmemory graphql-tag
26+
yarn add graphql graphql-tag @apollo/client
6027
```
6128

6229
In your app, create an `ApolloClient` instance:
6330

6431
```js
65-
import { ApolloClient } from 'apollo-client'
66-
import { createHttpLink } from 'apollo-link-http'
67-
import { InMemoryCache } from 'apollo-cache-inmemory'
32+
import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client/core'
6833

6934
// HTTP connection to the API
7035
const httpLink = createHttpLink({

packages/docs/src/migration/README.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# From vue-apollo 2 and Apollo 1
1+
# From vue-apollo 3
22

33
The main changes are related to the apollo client setup. Your components code shouldn't be affected. Apollo now uses a more flexible [apollo-link](https://github.com/apollographql/apollo-link) system that allows compositing multiple links together to add more features (like batching, offline support and more).
44

@@ -9,13 +9,13 @@ The main changes are related to the apollo client setup. Your components code sh
99
Before:
1010

1111
```
12-
npm install --save vue-apollo apollo-client
12+
npm install --save vue-apollo@next graphql apollo-client apollo-link apollo-link-http apollo-cache-inmemory graphql-tag
1313
```
1414

1515
After:
1616

1717
```
18-
npm install --save vue-apollo@next graphql apollo-client apollo-link apollo-link-http apollo-cache-inmemory graphql-tag
18+
npm install --save vue-apollo@next @apollo/client
1919
```
2020

2121
### Imports
@@ -24,17 +24,17 @@ Before:
2424

2525
```js
2626
import Vue from 'vue'
27-
import { ApolloClient, createBatchingNetworkInterface } from 'apollo-client'
27+
import { ApolloClient } from 'apollo-client'
28+
import { HttpLink } from 'apollo-link-http'
29+
import { InMemoryCache } from 'apollo-cache-inmemory'
2830
import VueApollo from '@vue/apollo-option'
2931
```
3032

3133
After:
3234

3335
```js
3436
import Vue from 'vue'
35-
import { ApolloClient } from 'apollo-client'
36-
import { HttpLink } from 'apollo-link-http'
37-
import { InMemoryCache } from 'apollo-cache-inmemory'
37+
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client/core'
3838
import VueApollo from '@vue/apollo-option'
3939
```
4040

@@ -168,29 +168,31 @@ Query reducers have been removed. Use the `update` API to update the cache now.
168168
Before:
169169

170170
```
171-
npm install --save subscriptions-transport-ws
171+
npm install --save apollo-link-ws apollo-utilities
172172
```
173173

174174
After:
175175

176176
```
177-
npm install --save apollo-link-ws apollo-utilities
177+
npm install --save @apollo/client
178178
```
179179

180180
### Imports
181181

182182
Before:
183183

184184
```js
185-
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws'
185+
import { split } from 'apollo-link'
186+
import { WebSocketLink } from 'apollo-link-ws'
187+
import { getMainDefinition } from 'apollo-utilities'
186188
```
187189

188190
After:
189191

190192
```js
191-
import { split } from 'apollo-link'
192-
import { WebSocketLink } from 'apollo-link-ws'
193-
import { getMainDefinition } from 'apollo-utilities'
193+
import { split } from '@apollo/client/core'
194+
import { WebSocketLink } from '@apollo/client/link/ws'
195+
import { getMainDefinition } from '@apollo/client/utilities'
194196
```
195197

196-
Learn more at the [official apollo documentation](https://www.apollographql.com/docs/react/2.0-migration.html).
198+
Learn more at the [official apollo documentation](https://www.apollographql.com/docs/react/2.0-migration.html).

0 commit comments

Comments
 (0)