Skip to content

Commit

Permalink
Replace 'cross-undici-fetch' with '@whatwg-node/fetch' since the prev…
Browse files Browse the repository at this point in the history
…ious one is deprecated (#4584)
  • Loading branch information
ardatan authored Jul 20, 2022
1 parent 3907d37 commit eda0da9
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .changeset/spicy-turkeys-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-tools/apollo-engine-loader': patch
'@graphql-tools/github-loader': patch
'@graphql-tools/url-loader': patch
---

Replace 'cross-undici-fetch' with '@whatwg-node/fetch' since the previous one is deprecated
2 changes: 1 addition & 1 deletion benchmark/federation/call.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { fetch } = require('cross-undici-fetch');
const { fetch } = require('@whatwg-node/fetch');

fetch('http://localhost:3000/stitching', {
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/apollo-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"dependencies": {
"@graphql-tools/utils": "8.8.0",
"cross-undici-fetch": "^0.4.11",
"@whatwg-node/fetch": "^0.0.2",
"sync-fetch": "0.4.1",
"tslib": "^2.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/apollo-engine/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Source, parseGraphQLSDL, AggregateError, BaseLoaderOptions, Loader } from '@graphql-tools/utils';
import { fetch } from 'cross-undici-fetch';
import { fetch } from '@whatwg-node/fetch';
import syncFetch from 'sync-fetch';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"dependencies": {
"@graphql-tools/utils": "8.8.0",
"@graphql-tools/graphql-tag-pluck": "7.3.0",
"cross-undici-fetch": "^0.4.11",
"@whatwg-node/fetch": "^0.0.2",
"sync-fetch": "0.4.1",
"tslib": "^2.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Loader, parseGraphQLSDL, parseGraphQLJSON, BaseLoaderOptions, Source }
import { GraphQLTagPluckOptions, gqlPluckFromCodeStringSync } from '@graphql-tools/graphql-tag-pluck';
import { parse } from 'graphql';
import syncFetch from 'sync-fetch';
import { fetch as asyncFetch } from 'cross-undici-fetch';
import { fetch as asyncFetch } from '@whatwg-node/fetch';

// github:owner/name#ref:path/to/file
function extractData(pointer: string): {
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@graphql-tools/wrap": "8.5.0",
"@n1ru4l/graphql-live-query": "^0.9.0",
"@types/ws": "^8.0.0",
"cross-undici-fetch": "^0.4.11",
"@whatwg-node/fetch": "^0.0.2",
"dset": "^3.1.2",
"extract-files": "^11.0.0",
"graphql-ws": "^5.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/url/src/defaultAsyncFetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetch } from 'cross-undici-fetch';
import { fetch } from '@whatwg-node/fetch';

export type AsyncFetchFn = typeof fetch;
export const defaultAsyncFetch: AsyncFetchFn = async (input, init) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/url/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { defaultSyncFetch, SyncFetchFn } from './defaultSyncFetch.js';
import { handleMultipartMixedResponse } from './handleMultipartMixedResponse.js';
import { handleEventStreamResponse } from './event-stream/handleEventStreamResponse.js';
import { addCancelToResponseStream } from './addCancelToResponseStream.js';
import { AbortController, FormData, File } from 'cross-undici-fetch';
import { AbortController, FormData, File } from '@whatwg-node/fetch';
import { isBlob, isGraphQLUpload, isPromiseLike, LEGACY_WS } from './utils.js';

export type FetchFn = AsyncFetchFn | SyncFetchFn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { handleEventStreamResponse } from '../src/event-stream/handleEventStreamResponse.js';
import { ReadableStream, Response } from 'cross-undici-fetch';
import { ReadableStream, Response } from '@whatwg-node/fetch';

describe('handleEventStreamResponse', () => {
const encoder = new TextEncoder();
Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/url/tests/url-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Server as WSServer } from 'ws';
import http from 'http';
import { SubscriptionServer } from 'subscriptions-transport-ws';
import { AsyncFetchFn, defaultAsyncFetch } from '../src/defaultAsyncFetch.js';
import { Response, File, Headers } from 'cross-undici-fetch';
import { Response, File, Headers } from '@whatwg-node/fetch';
import express from 'express';
import { inspect } from 'util';
import { createServer } from '@graphql-yoga/node';
Expand Down
2 changes: 1 addition & 1 deletion website/docs/batch-execution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type ExecutionRequest = {
A simple executor for a **remote service** looks like this:

```js
import { fetch } from 'cross-undici-fetch'
import { fetch } from '@whatwg-node/fetch'
import { print } from 'graphql'

async function myExecutor({ document, variables }) {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/connectors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ By this point in the documentation, you know how to generate a GraphQL.js schema
As you have read on the [resolvers page](/docs/resolvers/#resolver-result-format), resolvers in GraphQL.js can return Promises. This means it's easy to fetch data using any library that returns a promise for the result:

```js
import { fetch } from 'cross-undici-fetch'
import { fetch } from '@whatwg-node/fetch'

const resolverMap = {
Query: {
Expand All @@ -30,7 +30,7 @@ As you start to have more different resolvers that need to access the GitHub API

```js
// github-connector.js
import { fetch } from 'cross-undici-fetch'
import { fetch } from '@whatwg-node/fetch'

// This gives you a place to put GitHub API keys, for example
const { GITHUB_API_KEY, GITHUB_API_SECRET } = process.env
Expand Down
12 changes: 6 additions & 6 deletions website/docs/remote-schemas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ type Request = {
}
```

### GraphQL over HTTP executor with `cross-undici-fetch`
### GraphQL over HTTP executor with `@whatwg-node/fetch`

Basic usage

```js
import { fetch } from 'cross-undici-fetch'
import { fetch } from '@whatwg-node/fetch'
import { print } from 'graphql'
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap'
import { AsyncExecutor } from '@graphql-tools/utils'
Expand Down Expand Up @@ -84,7 +84,7 @@ export default async () => {
Authentication headers from context

```js
import { fetch } from 'cross-undici-fetch'
import { fetch } from '@whatwg-node/fetch'
import { print } from 'graphql'
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap'
import { AsyncExecutor } from '@graphql-tools/utils'
Expand Down Expand Up @@ -180,7 +180,7 @@ With this executor all operations (query, mutation and subscription) will be exe
```ts
import { wrapSchema, introspectSchema } from '@graphql-tools/wrap'
import { AsyncExecutor } from '@graphql-tools/utils'
import { fetch, AbortController } from 'cross-undici-fetch'
import { fetch, AbortController } from '@whatwg-node/fetch'
import { observableToAsyncIterable } from '@graphql-tools/utils'
import { createClient } from 'graphql-sse'
import { print } from 'graphql'
Expand Down Expand Up @@ -237,11 +237,11 @@ export default async () => {

Sometimes you only want to do subscription operations over WebSocket. In that case you have identify the operation and then call the corresponding executor for the operation type.

With this executor query and mutation operations will be executed over HTTP (using `cross-undici-fetch`) and subscription operations will be executed WebSocket (using `graphql-ws`).
With this executor query and mutation operations will be executed over HTTP (using `@whatwg-node/fetch`) and subscription operations will be executed WebSocket (using `graphql-ws`).

```ts
import { wrapSchema, introspectSchema } from '@graphql-tools/wrap'
import { fetch } from 'cross-undici-fetch'
import { fetch } from '@whatwg-node/fetch'
import { print, getOperationAST, OperationTypeNode } from 'graphql'
import { observableToAsyncIterable, AsyncExecutor } from '@graphql-tools/utils'
import { createClient } from 'graphql-ws'
Expand Down
2 changes: 1 addition & 1 deletion website/docs/schema-stitching/stitch-combining-schemas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ To include a remote schema in the combined gateway, you must provide at least th

```js
import { introspectSchema } from '@graphql-tools/wrap'
import { fetch } from 'cross-undici-fetch'
import { fetch } from '@whatwg-node/fetch'
import { print } from 'graphql'

async function remoteExecutor({ document, variables }) {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/schema-stitching/stitch-directives-sdl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ When setting up the stitched gateway, you'll need to do two things:
const { stitchSchemas } = require('@graphql-tools/stitch')
const { stitchingDirectivesTransformer } = require('@graphql-tools/stitching-directives')()
const { print, buildSchema } = require('graphql')
const { fetch } = require('cross-undici-fetch')
const { fetch } = require('@whatwg-node/fetch')

async function createGatewaySchema() {
const usersExec = createRemoteExecutor('http://localhost:4001/graphql')
Expand Down
2 changes: 1 addition & 1 deletion website/docs/schema-stitching/stitch-federation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ A working example can be found in the [Schema Stitching Handbook](https://github
const { stitchSchemas } = require('@graphql-tools/stitch')
const { federationToStitchingSDL, stitchingDirectives } = require('@graphql-tools/stitching-directives')
const { buildSchema, print } = require('graphql')
const { fetch } = require('cross-undici-fetch')
const { fetch } = require('@whatwg-node/fetch')
const stitchingConfig = stitchingDirectives()

const executor = async ({ document, variables }) => {
Expand Down
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4195,6 +4195,19 @@
"@webassemblyjs/ast" "1.11.1"
"@xtuc/long" "4.2.2"

"@whatwg-node/fetch@^0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@whatwg-node/fetch/-/fetch-0.0.2.tgz#4242c4e36714b5018ccac0ab76f4ab5a208fbc1c"
integrity sha512-qiZn8dYRg0POzUvmHBs7blLxl6DPL+b+Z0JUsGaj7/8PFe2BJG9onrUVX6OWh6Z9YhcYw8yu+wtCAme5ZMiCKQ==
dependencies:
abort-controller "^3.0.0"
busboy "^1.6.0"
form-data-encoder "^1.7.1"
formdata-node "^4.3.1"
node-fetch "^2.6.7"
undici "5.5.1"
web-streams-polyfill "^3.2.0"

"@wry/context@^0.6.0":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@wry/context/-/context-0.6.1.tgz#c3c29c0ad622adb00f6a53303c4f965ee06ebeb2"
Expand Down Expand Up @@ -5649,7 +5662,7 @@ cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

cross-undici-fetch@^0.4.11, cross-undici-fetch@^0.4.2:
cross-undici-fetch@^0.4.2:
version "0.4.11"
resolved "https://registry.yarnpkg.com/cross-undici-fetch/-/cross-undici-fetch-0.4.11.tgz#bef38dc729a01db6e07c84fee6de1089b5d3d0a4"
integrity sha512-pRp+EWewyOPYIeUvwOqCIqylCFWqlBwwr6nlZB38v3PhWxS1RYfSgHUJApYTT8jm71SbL5p4qg5kUQv6ZyS24A==
Expand Down

0 comments on commit eda0da9

Please sign in to comment.