Skip to content

Commit

Permalink
Add runtime dependency on node-fetch (#1970)
Browse files Browse the repository at this point in the history
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 apollographql/apollo-server#3546 as a fix for apollographql/apollo-server#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
  • Loading branch information
benweatherman authored Jul 18, 2022
1 parent b846d4f commit 0fd83f0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 26 deletions.
1 change: 1 addition & 0 deletions gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions gateway-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/config.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 '../..';
Expand Down
66 changes: 46 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0fd83f0

Please sign in to comment.