Skip to content

Commit 8d64701

Browse files
committedJul 24, 2022
Replace cross-undici-fetch with @whatwg-node/fetch
1 parent cffdbc2 commit 8d64701

File tree

24 files changed

+115
-60
lines changed

24 files changed

+115
-60
lines changed
 

‎benchmark/hello-world/check-server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require('cross-undici-fetch')
1+
require('@whatwg-node/fetch')
22
.fetch(
33
`http://localhost:4000/graphql?query=${encodeURIComponent(
44
'{ greetings }',

‎examples/azure-function/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AzureFunction, Context, HttpRequest } from '@azure/functions'
22
import { createServer } from '@graphql-yoga/common'
3-
import { Request } from 'cross-undici-fetch'
3+
import { Request } from '@whatwg-node/fetch'
44

55
const httpTrigger: AzureFunction = async function (
66
context: Context,

‎examples/cloudflare-modules/test/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import worker from '../src/index.js'
2-
import { Request } from 'cross-undici-fetch'
2+
import { Request } from '@whatwg-node/fetch'
33
import { getIntrospectionQuery } from 'graphql'
44

55
test('should render GraphiQL', async () => {

‎examples/error-handling/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"@graphql-yoga/node": "2.13.4",
11-
"cross-undici-fetch": "^0.4.13",
11+
"@whatwg-node/fetch": "^0.0.2",
1212
"graphql": "^16.1.0"
1313
},
1414
"devDependencies": {

‎examples/error-handling/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createServer, GraphQLYogaError } from '@graphql-yoga/node'
2-
import { fetch } from 'cross-undici-fetch'
2+
import { fetch } from '@whatwg-node/fetch'
33

44
const users = [
55
{

‎examples/service-worker/test/integration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getIntrospectionQuery } from 'graphql'
22
import { createServer } from '@graphql-yoga/common'
3-
import { Request } from 'cross-undici-fetch'
3+
import { Request } from '@whatwg-node/fetch'
44

55
const listenerMap = new Map<string, Set<EventListenerOrEventListenerObject>>()
66

‎package.json

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"resolutions": {
7979
"@changesets/apply-release-plan": "6.0.0",
8080
"graphql": "16.5.0",
81-
"cross-undici-fetch": "0.4.14",
8281
"@types/react": "17.0.39",
8382
"@types/react-dom": "17.0.17",
8483
"react": "17.0.2",

‎packages/common/__tests__/cors.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Request } from 'cross-undici-fetch'
1+
import { Request } from '@whatwg-node/fetch'
22
import {
33
getCORSHeadersByRequestAndOptions,
44
CORSOptions,

‎packages/common/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"@graphql-tools/schema": "^8.5.0",
7272
"@graphql-tools/utils": "^8.8.0",
7373
"@graphql-yoga/subscription": "^2.2.2",
74-
"cross-undici-fetch": "^0.4.13",
74+
"@whatwg-node/fetch": "^0.0.2",
7575
"dset": "^3.1.1",
7676
"tslib": "^2.3.1"
7777
},

‎packages/common/src/plugins/requestParser/POSTMultipart.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function parsePOSTMultipartRequest(
1717
try {
1818
requestBody = await request.formData()
1919
} catch (e: unknown) {
20-
// Trick for cross-undici-fetch errors on Node.js
20+
// Trick for @whatwg-node/fetch errors on Node.js
2121
// TODO: This needs a better solution
2222
if (
2323
e instanceof Error &&

‎packages/common/src/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
RequestParser,
3232
ResultProcessor,
3333
} from './plugins/types.js'
34-
import * as crossUndiciFetch from 'cross-undici-fetch'
34+
import * as crossUndiciFetch from '@whatwg-node/fetch'
3535
import { processRequest as processGraphQLParams } from './processRequest.js'
3636
import { defaultYogaLogger, titleBold, YogaLogger } from './logger.js'
3737
import { CORSPluginOptions, useCORS } from './plugins/useCORS.js'

‎packages/common/src/types.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,25 @@ export type FetchEvent = Event & {
116116
export type FetchAPI = {
117117
/**
118118
* WHATWG compliant Request object constructor
119-
* Default: `Request` from `cross-undici-fetch`
119+
* Default: `Request` from `@whatwg-node/fetch`
120120
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request
121121
*/
122122
Request: typeof Request
123123
/**
124124
* WHATWG compliant Response object constructor
125-
* Default: `Response` from `cross-undici-fetch`
125+
* Default: `Response` from `@whatwg-node/fetch`
126126
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response
127127
*/
128128
Response: typeof Response
129129
/**
130130
* WHATWG compliant fetch function
131-
* Default: `fetch` from `cross-undici-fetch`
131+
* Default: `fetch` from `@whatwg-node/fetch`
132132
* @see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
133133
*/
134134
fetch: typeof fetch
135135
/**
136136
* WHATWG compliant ReadableStream object constructor
137-
* Default: `ReadableStream` from `cross-undici-fetch`
137+
* Default: `ReadableStream` from `@whatwg-node/fetch`
138138
* @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
139139
*/
140140
ReadableStream: typeof ReadableStream

‎packages/graphiql/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
"vite": "2.9.14"
2929
},
3030
"dependencies": {
31-
"@graphql-tools/url-loader": "^7.11.0",
32-
"copy-to-clipboard": "^3.3.1",
33-
"graphiql": "^1.8.8",
34-
"graphiql-explorer": "^0.9.0",
35-
"graphql": "^16.3.0",
31+
"@graphql-tools/url-loader": "7.13.0",
32+
"copy-to-clipboard": "3.3.1",
33+
"graphiql": "1.8.8",
34+
"graphiql-explorer": "0.9.0",
35+
"graphql": "16.3.0",
3636
"react": "17.0.2",
3737
"react-dom": "17.0.2",
38-
"use-url-search-params": "^2.5.1",
39-
"json-bigint-patch": "^0.0.8"
38+
"use-url-search-params": "2.5.1",
39+
"json-bigint-patch": "0.0.8"
4040
},
4141
"main": "dist/yoga-graphiql.umd.js",
4242
"module": "dist/yoga-graphiql.es.js",

‎packages/graphiql/src/YogaGraphiQL.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import 'json-bigint-patch'
2323

2424
const getOperationWithFragments = (
2525
document: DocumentNode,
26-
operationName: string,
26+
operationName?: string,
2727
): DocumentNode => {
2828
const definitions = document.definitions.filter((definition) => {
2929
if (
@@ -121,12 +121,11 @@ export function YogaGraphiQL(props: YogaGraphiQLProps): React.ReactElement {
121121
return function fetcher(graphQLParams: FetcherParams, opts?: FetcherOpts) {
122122
const document = getOperationWithFragments(
123123
parse(graphQLParams.query),
124-
graphQLParams.operationName,
124+
graphQLParams.operationName ?? undefined,
125125
)
126-
127126
return executor({
128127
document,
129-
operationName: graphQLParams.operationName,
128+
operationName: graphQLParams.operationName ?? undefined,
130129
variables: graphQLParams.variables,
131130
extensions: {
132131
headers: opts?.headers,

‎packages/node/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
So Yoga now uses `node-fetch` by default which doesn't affect the existing users. User can configure `cross-undici-fetch` to revert back this behavior;
287287

288288
```ts
289-
import { create } from 'cross-undici-fetch'
289+
import { create } from '@whatwg-node/fetch'
290290

291291
createServer({
292292
fetchAPI: create({ useNodeFetch: false }),

‎packages/node/__tests__/integration.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'json-bigint-patch'
1515
import http from 'http'
1616
import { useLiveQuery } from '@envelop/live-query'
1717
import { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'
18-
import { AbortController, fetch, File, FormData } from 'cross-undici-fetch'
18+
import { AbortController, fetch, File, FormData } from '@whatwg-node/fetch'
1919
import { Plugin } from '@graphql-yoga/common'
2020
import { ExecutionResult } from '@graphql-tools/utils'
2121

‎packages/node/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"@graphql-tools/utils": "^8.8.0",
6868
"@graphql-yoga/common": "^2.12.3",
6969
"@graphql-yoga/subscription": "^2.2.2",
70-
"cross-undici-fetch": "^0.4.13",
70+
"@whatwg-node/fetch": "^0.0.2",
7171
"tslib": "^2.3.1"
7272
},
7373
"devDependencies": {

‎packages/node/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getNodeRequest, NodeRequest, sendNodeResponse } from './http-utils.js'
1010
import { YogaServer } from '@graphql-yoga/common'
1111
import type { YogaNodeServerOptions, AddressInfo } from './types.js'
1212
import { platform, release } from 'os'
13-
import { create } from 'cross-undici-fetch'
13+
import { createFetch } from '@whatwg-node/fetch'
1414

1515
class YogaNodeServer<
1616
TServerContext extends Record<string, any>,
@@ -35,7 +35,7 @@ class YogaNodeServer<
3535
multipart: options?.multipart !== false,
3636
fetchAPI:
3737
options?.fetchAPI ??
38-
create({
38+
createFetch({
3939
useNodeFetch: true,
4040
formDataLimits:
4141
typeof options?.multipart === 'object'

‎packages/node/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { YogaServerOptions } from '@graphql-yoga/common'
2-
import type { FormDataLimits } from 'cross-undici-fetch'
2+
import type { FormDataLimits } from '@whatwg-node/fetch'
33
import type { ServerOptions as HttpsServerOptions } from 'https'
44

55
/**

‎patches/@changesets+assemble-release-plan+5.1.2.patch ‎patches/@changesets+assemble-release-plan+5.1.3.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/node_modules/@changesets/assemble-release-plan/dist/assemble-release-plan.cjs.dev.js b/node_modules/@changesets/assemble-release-plan/dist/assemble-release-plan.cjs.dev.js
2-
index 8c8f6fd..174fd69 100644
2+
index f05ea74..9a0ed16 100644
33
--- a/node_modules/@changesets/assemble-release-plan/dist/assemble-release-plan.cjs.dev.js
44
+++ b/node_modules/@changesets/assemble-release-plan/dist/assemble-release-plan.cjs.dev.js
55
@@ -130,18 +130,9 @@ function determineDependents({

‎patches/@changesets+cli+2.22.0.patch ‎patches/@changesets+cli+2.23.2.patch

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/node_modules/@changesets/cli/dist/cli.cjs.dev.js b/node_modules/@changesets/cli/dist/cli.cjs.dev.js
2-
index 129ae05..9b5daeb 100644
2+
index 4b68b5d..55e34bc 100644
33
--- a/node_modules/@changesets/cli/dist/cli.cjs.dev.js
44
+++ b/node_modules/@changesets/cli/dist/cli.cjs.dev.js
5-
@@ -639,7 +639,7 @@ const getLastJsonObjectFromString = str => {
5+
@@ -649,7 +649,7 @@ const getLastJsonObjectFromString = str => {
66
return null;
77
};
88

@@ -12,10 +12,10 @@ index 129ae05..9b5daeb 100644
1212

1313
function jsonParse(input) {
1414
diff --git a/node_modules/@changesets/cli/dist/cli.cjs.prod.js b/node_modules/@changesets/cli/dist/cli.cjs.prod.js
15-
index ee3d78e..dc2a8c7 100644
15+
index 5c4828d..3694ebf 100644
1616
--- a/node_modules/@changesets/cli/dist/cli.cjs.prod.js
1717
+++ b/node_modules/@changesets/cli/dist/cli.cjs.prod.js
18-
@@ -354,7 +354,7 @@ const getLastJsonObjectFromString = str => {
18+
@@ -359,7 +359,7 @@ const getLastJsonObjectFromString = str => {
1919
}
2020
}
2121
return null;
@@ -25,10 +25,10 @@ index ee3d78e..dc2a8c7 100644
2525
function jsonParse(input) {
2626
try {
2727
diff --git a/node_modules/@changesets/cli/dist/cli.esm.js b/node_modules/@changesets/cli/dist/cli.esm.js
28-
index 19806a8..72859ff 100644
28+
index d715066..bad525f 100644
2929
--- a/node_modules/@changesets/cli/dist/cli.esm.js
3030
+++ b/node_modules/@changesets/cli/dist/cli.esm.js
31-
@@ -616,7 +616,7 @@ const getLastJsonObjectFromString = str => {
31+
@@ -626,7 +626,7 @@ const getLastJsonObjectFromString = str => {
3232
return null;
3333
};
3434

‎website/docs/features/error-masking.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Let's setup a simple schema that calls a remote service that is unavailable.
1616

1717
```ts
1818
import { createServer } from '@graphql-yoga/node'
19-
import { fetch } from 'cross-undici-fetch'
19+
import { fetch } from '@whatwg-node/fetch'
2020

2121
// Provide your schema
2222
const server = createServer({
@@ -99,7 +99,7 @@ node server.js
9999

100100
```ts
101101
import { createServer } from '@graphql-yoga/node'
102-
import { fetch } from 'cross-undici-fetch'
102+
import { fetch } from '@whatwg-node/fetch'
103103

104104
// Provide your schema
105105
const server = createServer({

‎website/docs/integrations/z-other-environments.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ GraphQL Yoga understands [WHATWG `Request` object](https://developer.mozilla.org
1111

1212
```ts
1313
import { createServer } from '@graphql-yoga/common'
14-
import { Request } from 'cross-undici-fetch' // or fetch-like library
14+
import { Request } from '@whatwg-node/fetch' // or fetch-like library
1515
1616
const yoga = createServer<MyRandomCtx>()
1717

0 commit comments

Comments
 (0)
Please sign in to comment.