From 0fd83f0b2b5435440962df73cfee633153695cde Mon Sep 17 00:00:00 2001 From: weatherman Date: Mon, 18 Jul 2022 17:50:44 -0500 Subject: [PATCH] Add runtime dependency on node-fetch (#1970) We use `node-fetch` during runtime for some of the public methods in `RemoteGraphQLDataSource`. Using `node-fetch@2` because v3 is ESM-only. There's already a renovate rule to keep things from going to v3. We should probably break the interfaces that are using `node-fetch`'s classes, since they aren't used by the default implementation after switching to `make-fetch-happen`. ### Other detritus - **Remove `@types/node-fetch`** This was originally included in https://github.com/apollographql/apollo-server/pull/3546 as a fix for https://github.com/apollographql/apollo-server/issues/3471. - **Change some imports to use `type`** so there's no runtime dependency for things that are just using types. - **Remove `pretty-format`** since that's not a runtime thing --- gateway-js/CHANGELOG.md | 1 + gateway-js/package.json | 3 +- gateway-js/src/config.ts | 2 +- gateway-js/src/executeQueryPlan.ts | 2 +- .../IntrospectAndCompose/index.ts | 2 +- .../loadServicesFromRemoteEndpoint.ts | 2 +- package-lock.json | 66 +++++++++++++------ 7 files changed, 52 insertions(+), 26 deletions(-) diff --git a/gateway-js/CHANGELOG.md b/gateway-js/CHANGELOG.md index 5b40bc7e3..270a0aae7 100644 --- a/gateway-js/CHANGELOG.md +++ b/gateway-js/CHANGELOG.md @@ -16,6 +16,7 @@ This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The not honored in any way. As this change reject such applications (at composition time), it could theoretically require to remove some existing (ignored) directive applications within a `@key`, `@provides` or `@requires`. - Move `DEFAULT_UPLINK_ENDPOINTS` to static member of `UplinkSupergraphManager` [PR #1977](https://github.com/apollographql/federation/pull/1977). +- Add `node-fetch` as a runtime dependency [PR #1970](https://github.com/apollographql/federation/pull/1970). ## 2.1.0-alpha.0 diff --git a/gateway-js/package.json b/gateway-js/package.json index 62d456aab..ec814aac9 100644 --- a/gateway-js/package.json +++ b/gateway-js/package.json @@ -35,7 +35,6 @@ "@apollo/utils.logger": "^1.0.0", "@josephg/resolvable": "^1.0.1", "@opentelemetry/api": "^1.0.1", - "@types/node-fetch": "2.6.2", "apollo-reporting-protobuf": "^0.8.0 || ^3.0.0", "apollo-server-caching": "^0.7.0 || ^3.0.0", "apollo-server-core": "^2.23.0 || ^3.0.0", @@ -44,7 +43,7 @@ "async-retry": "^1.3.3", "loglevel": "^1.6.1", "make-fetch-happen": "^10.1.2", - "pretty-format": "^28.0.0" + "node-fetch": "^2.6.7" }, "peerDependencies": { "graphql": "^16.0.0" diff --git a/gateway-js/src/config.ts b/gateway-js/src/config.ts index 5eddbcff6..a5cc866f2 100644 --- a/gateway-js/src/config.ts +++ b/gateway-js/src/config.ts @@ -1,5 +1,5 @@ import { GraphQLError, GraphQLSchema } from 'graphql'; -import { HeadersInit } from 'node-fetch'; +import type { HeadersInit } from 'node-fetch'; import { GraphQLRequestContextExecutionDidStart } from 'apollo-server-types'; import type { Logger } from '@apollo/utils.logger'; import { GraphQLDataSource } from './datasources/types'; diff --git a/gateway-js/src/executeQueryPlan.ts b/gateway-js/src/executeQueryPlan.ts index 1d57e8083..ce8f13610 100644 --- a/gateway-js/src/executeQueryPlan.ts +++ b/gateway-js/src/executeQueryPlan.ts @@ -614,7 +614,7 @@ function downstreamServiceError( let codeDef = errorCodeDef(originalError); // It's possible the orignal has a code, but not one we know about (one generated by the underlying `GraphQLDataSource`, - // which we don't control). In that case, we want to use that code (and have thus no `ErrorCodeDefinition` usable). + // which we don't control). In that case, we want to use that code (and have thus no `ErrorCodeDefinition` usable). if (!codeDef && extensions?.code) { return new GraphQLError(message, errorOptions); } diff --git a/gateway-js/src/supergraphManagers/IntrospectAndCompose/index.ts b/gateway-js/src/supergraphManagers/IntrospectAndCompose/index.ts index 4be9ab65e..02ca1b228 100644 --- a/gateway-js/src/supergraphManagers/IntrospectAndCompose/index.ts +++ b/gateway-js/src/supergraphManagers/IntrospectAndCompose/index.ts @@ -1,5 +1,5 @@ import type { Logger } from '@apollo/utils.logger'; -import { HeadersInit } from 'node-fetch'; +import type { HeadersInit } from 'node-fetch'; import resolvable from '@josephg/resolvable'; import { ServiceEndpointDefinition, diff --git a/gateway-js/src/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.ts b/gateway-js/src/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.ts index b357c83a7..6fccd5cc4 100644 --- a/gateway-js/src/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.ts +++ b/gateway-js/src/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.ts @@ -1,6 +1,6 @@ import { GraphQLRequest } from 'apollo-server-types'; import { parse } from 'graphql'; -import { Headers, HeadersInit } from 'node-fetch'; +import { Headers, type HeadersInit } from 'node-fetch'; import { ServiceDefinition } from '@apollo/federation-internals'; import { GraphQLDataSource, GraphQLDataSourceRequestKind } from '../../datasources/types'; import { SERVICE_DEFINITION_QUERY } from '../..'; diff --git a/package-lock.json b/package-lock.json index 94158563f..14a0542a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -104,7 +104,6 @@ "@apollo/utils.logger": "^1.0.0", "@josephg/resolvable": "^1.0.1", "@opentelemetry/api": "^1.0.1", - "@types/node-fetch": "2.6.2", "apollo-reporting-protobuf": "^0.8.0 || ^3.0.0", "apollo-server-caching": "^0.7.0 || ^3.0.0", "apollo-server-core": "^2.23.0 || ^3.0.0", @@ -113,7 +112,7 @@ "async-retry": "^1.3.3", "loglevel": "^1.6.1", "make-fetch-happen": "^10.1.2", - "pretty-format": "^28.0.0" + "node-fetch": "^2.6.7" }, "engines": { "node": ">=12.13.0" @@ -4634,12 +4633,14 @@ "node_modules/@types/node": { "version": "12.20.55", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", - "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==" + "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==", + "dev": true }, "node_modules/@types/node-fetch": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.2.tgz", "integrity": "sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==", + "dev": true, "dependencies": { "@types/node": "*", "form-data": "^3.0.0" @@ -5567,6 +5568,7 @@ }, "node_modules/asynckit": { "version": "0.4.0", + "dev": true, "license": "MIT" }, "node_modules/at-least-node": { @@ -6616,6 +6618,7 @@ }, "node_modules/combined-stream": { "version": "1.0.8", + "dev": true, "license": "MIT", "dependencies": { "delayed-stream": "~1.0.0" @@ -7218,6 +7221,7 @@ }, "node_modules/delayed-stream": { "version": "1.0.0", + "dev": true, "license": "MIT", "engines": { "node": ">=0.4.0" @@ -8467,6 +8471,7 @@ }, "node_modules/form-data": { "version": "3.0.1", + "dev": true, "license": "MIT", "dependencies": { "asynckit": "^0.4.0", @@ -13145,6 +13150,7 @@ }, "node_modules/mime-db": { "version": "1.51.0", + "dev": true, "license": "MIT", "engines": { "node": ">= 0.6" @@ -13152,6 +13158,7 @@ }, "node_modules/mime-types": { "version": "2.1.34", + "dev": true, "license": "MIT", "dependencies": { "mime-db": "1.51.0" @@ -13635,7 +13642,8 @@ }, "node_modules/node-fetch": { "version": "2.6.7", - "license": "MIT", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -13651,17 +13659,15 @@ } } }, - "node_modules/node-fetch/node_modules/tr46": { - "version": "0.0.3", - "license": "MIT" - }, "node_modules/node-fetch/node_modules/webidl-conversions": { "version": "3.0.1", - "license": "BSD-2-Clause" + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "node_modules/node-fetch/node_modules/whatwg-url": { "version": "5.0.0", - "license": "MIT", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -17422,6 +17428,11 @@ "node": ">= 4.0.0" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, "node_modules/trim-newlines": { "version": "3.0.1", "dev": true, @@ -18692,7 +18703,6 @@ "@apollo/utils.logger": "^1.0.0", "@josephg/resolvable": "^1.0.1", "@opentelemetry/api": "^1.0.1", - "@types/node-fetch": "2.6.2", "apollo-reporting-protobuf": "^0.8.0 || ^3.0.0", "apollo-server-caching": "^0.7.0 || ^3.0.0", "apollo-server-core": "^2.23.0 || ^3.0.0", @@ -18701,7 +18711,7 @@ "async-retry": "^1.3.3", "loglevel": "^1.6.1", "make-fetch-happen": "^10.1.2", - "pretty-format": "^28.0.0" + "node-fetch": "^2.6.7" }, "dependencies": { "@npmcli/fs": { @@ -22134,12 +22144,14 @@ "@types/node": { "version": "12.20.55", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", - "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==" + "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==", + "dev": true }, "@types/node-fetch": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.2.tgz", "integrity": "sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==", + "dev": true, "requires": { "@types/node": "*", "form-data": "^3.0.0" @@ -22750,7 +22762,8 @@ } }, "asynckit": { - "version": "0.4.0" + "version": "0.4.0", + "dev": true }, "at-least-node": { "version": "1.0.0", @@ -23476,6 +23489,7 @@ }, "combined-stream": { "version": "1.0.8", + "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -23908,7 +23922,8 @@ } }, "delayed-stream": { - "version": "1.0.0" + "version": "1.0.0", + "dev": true }, "delegates": { "version": "1.0.0", @@ -24781,6 +24796,7 @@ }, "form-data": { "version": "3.0.1", + "dev": true, "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -28037,10 +28053,12 @@ "dev": true }, "mime-db": { - "version": "1.51.0" + "version": "1.51.0", + "dev": true }, "mime-types": { "version": "2.1.34", + "dev": true, "requires": { "mime-db": "1.51.0" } @@ -28362,18 +28380,21 @@ }, "node-fetch": { "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", "requires": { "whatwg-url": "^5.0.0" }, "dependencies": { - "tr46": { - "version": "0.0.3" - }, "webidl-conversions": { - "version": "3.0.1" + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "whatwg-url": { "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", "requires": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -30939,6 +30960,11 @@ } } }, + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, "trim-newlines": { "version": "3.0.1", "dev": true