Skip to content

Commit d9fe5df

Browse files
seanparmeleegatsbybotLekoArts
authored
feat(gatsby-source-graphql): upgrade apollo & graphql-tools deps (#34772)
Co-authored-by: gatsbybot <[email protected]> Co-authored-by: LekoArts <[email protected]>
1 parent fb082bc commit d9fe5df

File tree

10 files changed

+161
-219
lines changed

10 files changed

+161
-219
lines changed

docs/docs/how-to/plugins-and-themes/creating-a-source-plugin.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,14 @@ Now in your plugin's `gatsby-node.js` file, you can implement a new API, called
505505
Import the `createRemoteFileNode` helper from `gatsby-source-filesystem`, which will download a file from a remote location and create a `File` node for you.
506506

507507
```javascript:title=source-plugin/gatsby-node.js
508-
const { ApolloClient } = require("apollo-client")
509-
const { InMemoryCache } = require("apollo-cache-inmemory")
510-
const { split } = require("apollo-link")
511-
const { HttpLink } = require("apollo-link-http")
512-
const { WebSocketLink } = require("apollo-link-ws")
513-
const { getMainDefinition } = require("apollo-utilities")
508+
const {
509+
ApolloClient,
510+
InMemoryCache,
511+
split,
512+
HttpLink,
513+
} = require("@apollo/client")
514+
const { WebSocketLink } = require("@apollo/client/link/ws")
515+
const { getMainDefinition } = require("@apollo/client/utilities")
514516
const fetch = require("node-fetch")
515517
const gql = require("graphql-tag")
516518
const WebSocket = require("ws")

examples/creating-source-plugins/source-plugin/gatsby-node.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const { createRemoteFileNode } = require(`gatsby-source-filesystem`)
22
const WebSocket = require("ws")
3-
const { ApolloClient } = require("apollo-client")
4-
const { InMemoryCache } = require("apollo-cache-inmemory")
5-
const { split } = require("apollo-link")
6-
const { HttpLink } = require("apollo-link-http")
7-
const { WebSocketLink } = require("apollo-link-ws")
8-
const { getMainDefinition } = require("apollo-utilities")
3+
const {
4+
ApolloClient,
5+
InMemoryCache,
6+
split,
7+
HttpLink,
8+
} = require("@apollo/client")
9+
const { WebSocketLink } = require("@apollo/client/link/ws")
10+
const { getMainDefinition } = require("@apollo/client/utilities")
911
const fetch = require("node-fetch")
1012
const gql = require("graphql-tag")
1113

@@ -145,9 +147,7 @@ exports.sourceNodes = async function sourceNodes(
145147

146148
// touch nodes to ensure they aren't garbage collected
147149
getNodesByType(POST_NODE_TYPE).forEach(node => touchNode(node))
148-
getNodesByType(AUTHOR_NODE_TYPE).forEach(node =>
149-
touchNode(node)
150-
)
150+
getNodesByType(AUTHOR_NODE_TYPE).forEach(node => touchNode(node))
151151

152152
// listen for updates using subscriptions from the API
153153
if (pluginOptions.preview) {

examples/creating-source-plugins/source-plugin/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
"author": "Kyle Gill <[email protected]>",
1414
"license": "MIT",
1515
"dependencies": {
16-
"apollo-cache-inmemory": "^1.6.6",
17-
"apollo-client": "^2.6.10",
18-
"apollo-link": "^1.2.14",
19-
"apollo-link-http": "^1.5.17",
20-
"apollo-link-ws": "^1.0.20",
21-
"apollo-utilities": "^1.3.4",
16+
"@apollo/client": "^3.5.8",
2217
"gatsby-source-filesystem": "next",
2318
"graphql": "^15.3.0",
2419
"graphql-tag": "^2.11.0",

packages/gatsby-source-graphql/README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,26 +154,26 @@ module.exports = {
154154

155155
## Composing Apollo Links for production network setup
156156

157-
Network requests can fail, return errors or take too long. Use [Apollo Link](https://www.apollographql.com/docs/link/) to
157+
Network requests can fail, return errors or take too long. Use [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/) to
158158
add retries, error handling, logging and more to your GraphQL requests.
159159

160160
Use the plugin's `createLink` option to add a custom Apollo Link to your GraphQL requests.
161161

162162
You can compose different types of links, depending on the functionality you're trying to achieve.
163163
The most common links are:
164164

165-
- `apollo-link-retry` for retrying queries that fail or time out
166-
- `apollo-link-error` for error handling
167-
- `apollo-link-http` for sending queries in http requests (used by default)
165+
- `@apollo/client/link/retry` for retrying queries that fail or time out
166+
- `@apollo/client/link/error` for error handling
167+
- `@apollo/client/link/http` for sending queries in http requests (used by default)
168168

169169
For more explanation of how Apollo Links work together, check out this Medium article: [Productionizing Apollo Links](https://medium.com/@joanvila/productionizing-apollo-links-4cdc11d278eb).
170170

171-
Here's an example of using the HTTP link with retries (using [apollo-link-retry](https://www.npmjs.com/package/apollo-link-retry)):
171+
Here's an example of using the HTTP link with retries (using [@apollo/client/link/retry](https://www.apollographql.com/docs/react/api/link/apollo-link-retry/)):
172172

173173
```js
174174
// gatsby-config.js
175-
const { createHttpLink } = require(`apollo-link-http`)
176-
const { RetryLink } = require(`apollo-link-retry`)
175+
const { createHttpLink, from } = require(`@apollo/client`)
176+
const { RetryLink } = require(`@apollo/client/link/retry`)
177177

178178
const retryLink = new RetryLink({
179179
delay: {
@@ -200,10 +200,7 @@ module.exports = {
200200
// `pluginOptions`: all plugin options
201201
// (i.e. in this example object with keys `typeName`, `fieldName`, `url`, `createLink`)
202202
createLink: pluginOptions =>
203-
ApolloLink.from([
204-
retryLink,
205-
createHttpLink({ uri: pluginOptions.url }),
206-
]),
203+
from([retryLink, createHttpLink({ uri: pluginOptions.url })]),
207204
},
208205
},
209206
],

packages/gatsby-source-graphql/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
"url": "https://github.com/gatsbyjs/gatsby/issues"
88
},
99
"dependencies": {
10+
"@apollo/client": "^3.5.8",
1011
"@babel/runtime": "^7.15.4",
11-
"@graphql-tools/links": "^7.1.0",
12-
"@graphql-tools/utils": "^7.10.0",
13-
"@graphql-tools/wrap": "^7.0.8",
14-
"apollo-link": "1.2.14",
15-
"apollo-link-http": "^1.5.17",
12+
"@graphql-tools/links": "^8.2.1",
13+
"@graphql-tools/utils": "^8.6.1",
14+
"@graphql-tools/wrap": "^8.3.3",
1615
"dataloader": "^2.0.0",
1716
"gatsby-core-utils": "^3.11.0-next.0",
1817
"invariant": "^2.2.4",

packages/gatsby-source-graphql/src/__tests__/gatsby-node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ jest.mock(`@graphql-tools/wrap`, () => {
55
RenameTypes: jest.fn(),
66
}
77
})
8-
jest.mock(`apollo-link-http`, () => {
8+
jest.mock(`@apollo/client`, () => {
99
return {
1010
createHttpLink: jest.fn(),
1111
}
1212
})
13-
const { createHttpLink } = require(`apollo-link-http`)
13+
const { createHttpLink } = require(`@apollo/client`)
1414
const { testPluginOptionsSchema } = require(`gatsby-plugin-utils`)
1515
jest.mock(`gatsby/graphql`, () => {
1616
const graphql = jest.requireActual(`gatsby/graphql`)

packages/gatsby-source-graphql/src/batching/__tests__/dataloader-link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { parse } = require(`gatsby/graphql`)
2-
const { execute } = require(`apollo-link`)
2+
const { execute } = require(`@apollo/client`)
33
const { createDataloaderLink } = require(`../dataloader-link`)
44

55
const sampleQuery = parse(`{ foo }`)

packages/gatsby-source-graphql/src/batching/dataloader-link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const DataLoader = require(`dataloader`)
2-
const { ApolloLink, Observable } = require(`apollo-link`)
2+
const { ApolloLink, Observable } = require(`@apollo/client`)
33
const { print } = require(`gatsby/graphql`)
44
const { merge, resolveResult } = require(`./merge-queries`)
55

packages/gatsby-source-graphql/src/gatsby-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
RenameTypes,
77
} = require(`@graphql-tools/wrap`)
88
const { linkToExecutor } = require(`@graphql-tools/links`)
9-
const { createHttpLink } = require(`apollo-link-http`)
9+
const { createHttpLink } = require(`@apollo/client`)
1010
const { fetchWrapper } = require(`./fetch`)
1111
const { createDataloaderLink } = require(`./batching/dataloader-link`)
1212

0 commit comments

Comments
 (0)