From f75e0490e475c2b92534c23904e0a6554538c073 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Tue, 12 May 2020 10:50:35 +0000 Subject: [PATCH 1/7] comment: Leave traces/suggestions about future work. Ref: https://github.com/apollographql/apollo-server/pull/3988#discussion_r414676152 Apollo-Orig-Commit-AS: apollographql/apollo-server@18d95fd7f30bba196f7b0b62abdcff6bcb0eae18 --- gateway-js/src/executeQueryPlan.ts | 8 +++----- gateway-js/src/index.ts | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gateway-js/src/executeQueryPlan.ts b/gateway-js/src/executeQueryPlan.ts index 72116c8e83..2c9c3c4378 100644 --- a/gateway-js/src/executeQueryPlan.ts +++ b/gateway-js/src/executeQueryPlan.ts @@ -88,11 +88,9 @@ export async function executeQueryPlan( }, rootValue: data, variableValues: requestContext.request.variables, - // FIXME: GraphQL extensions currently wraps every field and creates - // a field resolver. Because of this, when using with ApolloServer - // the defaultFieldResolver isn't called. We keep this here - // because it is the correct solution and when ApolloServer removes - // GraphQLExtensions this will be how alias support is maintained + // We have a special field resolver which ensures we support aliases. + // FIXME: It's _possible_ this will change after `graphql-extensions` is + // deprecated, though not certain. See here, also: https://git.io/Jf8cS. fieldResolver: defaultFieldResolverWithAliasSupport, })); } catch (error) { diff --git a/gateway-js/src/index.ts b/gateway-js/src/index.ts index 1daf6097d6..d74269f029 100644 --- a/gateway-js/src/index.ts +++ b/gateway-js/src/index.ts @@ -476,6 +476,10 @@ export class ApolloGateway implements GraphQLService { this.logger.debug('Schema loaded and ready for execution'); + // FIXME: The comment below may change when `graphql-extensions` is + // removed, as it will be soon. It's not clear if this will be temporary, + // as is suggested, after that time, because we still very much need to + // do this special alias resolving. Original comment: // this is a temporary workaround for GraphQLFieldExtensions automatic // wrapping of all fields when using ApolloServer. Here we wrap all fields // with support for resolving aliases as part of the root value which From 1244190f2a7471e61dad4752ab5675e86f1b0646 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Wed, 13 May 2020 13:00:30 +0300 Subject: [PATCH 2/7] Release - apollo-cache-control@0.11.0-alpha.0 - apollo-datasource-rest@0.9.2-alpha.0 - apollo-engine-reporting@2.0.0-alpha.0 - @apollo/federation@0.16.1-alpha.0 - @apollo/gateway@0.16.1-alpha.0 - apollo-server-azure-functions@2.14.0-alpha.0 - apollo-server-cloud-functions@2.14.0-alpha.0 - apollo-server-cloudflare@2.14.0-alpha.0 - apollo-server-core@2.14.0-alpha.0 - apollo-server-express@2.14.0-alpha.0 - apollo-server-fastify@2.14.0-alpha.0 - apollo-server-hapi@2.14.0-alpha.0 - apollo-server-integration-testsuite@2.14.0-alpha.0 - apollo-server-koa@2.14.0-alpha.0 - apollo-server-lambda@2.14.0-alpha.0 - apollo-server-micro@2.14.0-alpha.0 - apollo-server-plugin-base@0.9.0-alpha.0 - apollo-server-plugin-response-cache@0.5.2-alpha.0 - apollo-server-testing@2.14.0-alpha.0 - apollo-server-types@0.5.0-alpha.0 - apollo-server@2.14.0-alpha.0 - apollo-tracing@0.11.0-alpha.0 - graphql-extensions@0.12.2-alpha.0 Apollo-Orig-Commit-AS: apollographql/apollo-server@bfef89b8cc44d4bd94f9d5fcd3df8941de526360 --- federation-js/package.json | 2 +- gateway-js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/federation-js/package.json b/federation-js/package.json index 4017608c05..520e31a6d7 100644 --- a/federation-js/package.json +++ b/federation-js/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/federation", - "version": "0.16.0", + "version": "0.16.1-alpha.0", "description": "Apollo Federation Utilities", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/gateway-js/package.json b/gateway-js/package.json index 85a1820411..f15746178f 100644 --- a/gateway-js/package.json +++ b/gateway-js/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/gateway", - "version": "0.16.0", + "version": "0.16.1-alpha.0", "description": "Apollo Gateway", "author": "opensource@apollographql.com", "main": "dist/index.js", From 5d62962d077b2f606112eeb4151b0c8e8bd68c76 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Tue, 19 May 2020 12:47:19 +0300 Subject: [PATCH 3/7] Release - apollo-cache-control@0.11.0-alpha.1 - apollo-datasource-rest@0.9.2-alpha.1 - apollo-engine-reporting-protobuf@0.5.1-alpha.1 - apollo-engine-reporting@2.0.0-alpha.1 - @apollo/gateway@0.16.1-alpha.1 - apollo-server-azure-functions@2.14.0-alpha.1 - apollo-server-cloud-functions@2.14.0-alpha.1 - apollo-server-cloudflare@2.14.0-alpha.1 - apollo-server-core@2.14.0-alpha.1 - apollo-server-express@2.14.0-alpha.1 - apollo-server-fastify@2.14.0-alpha.1 - apollo-server-hapi@2.14.0-alpha.1 - apollo-server-integration-testsuite@2.14.0-alpha.1 - apollo-server-koa@2.14.0-alpha.1 - apollo-server-lambda@2.14.0-alpha.1 - apollo-server-micro@2.14.0-alpha.1 - apollo-server-plugin-base@0.9.0-alpha.1 - apollo-server-plugin-operation-registry@0.3.2-alpha.0 - apollo-server-plugin-response-cache@0.5.2-alpha.1 - apollo-server-testing@2.14.0-alpha.1 - apollo-server-types@0.5.0-alpha.1 - apollo-server@2.14.0-alpha.1 - apollo-tracing@0.11.0-alpha.1 - graphql-extensions@0.12.2-alpha.1 Apollo-Orig-Commit-AS: apollographql/apollo-server@6b8a4366363c27a8d828e733edef4d06ecc1cd55 --- gateway-js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway-js/package.json b/gateway-js/package.json index 1f57815760..23d5b32986 100644 --- a/gateway-js/package.json +++ b/gateway-js/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/gateway", - "version": "0.16.1-alpha.0", + "version": "0.16.1-alpha.1", "description": "Apollo Gateway", "author": "opensource@apollographql.com", "main": "dist/index.js", From 54774311bf3c9fa72dd789457d8d61121df8a193 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Wed, 20 May 2020 17:28:11 +0300 Subject: [PATCH 4/7] Release - apollo-engine-reporting@2.0.0-alpha.2 - @apollo/gateway@0.16.1-alpha.2 - apollo-server-azure-functions@2.14.0-alpha.2 - apollo-server-cloud-functions@2.14.0-alpha.2 - apollo-server-cloudflare@2.14.0-alpha.2 - apollo-server-core@2.14.0-alpha.2 - apollo-server-express@2.14.0-alpha.2 - apollo-server-fastify@2.14.0-alpha.2 - apollo-server-hapi@2.14.0-alpha.2 - apollo-server-integration-testsuite@2.14.0-alpha.2 - apollo-server-koa@2.14.0-alpha.2 - apollo-server-lambda@2.14.0-alpha.2 - apollo-server-micro@2.14.0-alpha.2 - apollo-server-testing@2.14.0-alpha.2 - apollo-server@2.14.0-alpha.2 Apollo-Orig-Commit-AS: apollographql/apollo-server@36afcd616858a772c6c46ee4fe4544f54c69ab75 --- gateway-js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway-js/package.json b/gateway-js/package.json index 23d5b32986..8d9088496e 100644 --- a/gateway-js/package.json +++ b/gateway-js/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/gateway", - "version": "0.16.1-alpha.1", + "version": "0.16.1-alpha.2", "description": "Apollo Gateway", "author": "opensource@apollographql.com", "main": "dist/index.js", From 41d4e53f1f7101b5452d20b1b9acd63b7f1368ef Mon Sep 17 00:00:00 2001 From: Jeff Hampton Date: Wed, 27 May 2020 07:35:45 -0500 Subject: [PATCH 5/7] gateway: Support custom `fetcher` for RemoteGraphQLDataSource. (apollographql/apollo-server#4149) Co-authored-by: Jesse Rosenberger Apollo-Orig-Commit-AS: apollographql/apollo-server@489139c7bb0e112f4eacfb8f9a88b0fb80874013 --- gateway-js/CHANGELOG.md | 6 ++++- .../datasources/RemoteGraphQLDataSource.ts | 5 +++- .../__tests__/RemoteGraphQLDataSource.test.ts | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/gateway-js/CHANGELOG.md b/gateway-js/CHANGELOG.md index 6d60093e03..0ce314f654 100644 --- a/gateway-js/CHANGELOG.md +++ b/gateway-js/CHANGELOG.md @@ -4,7 +4,11 @@ > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section. -- _Nothing yet! Stay tuned._ +- __NEW__: Provide the ability to pass a custom `fetcher` during `RemoteGraphQLDataSource` construction to be used when executing operations against downstream services. Providing a custom `fetcher` may be necessary to accommodate more advanced needs, e.g., configuring custom TLS certificates for internal services. [PR #4149](https://github.com/apollographql/apollo-server/pull/4149) + + The `fetcher` specified should be a compliant implementor of the [Fetch API standard](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This addition compliments, though is still orthognonal to, similar behavior originally introduced in [#3783](https://github.com/apollographql/apollo-server/pull/3783), which allowed customization of the implementation used to fetch _gateway configuration and federated SDL from services_ in managed and unmanaged modes, but didn't affect the communication that takes place during _operation execution_. + + For now, the default `fetcher` will remain the same ([`node-fetch`](https://npm.im/node-fetch)) implementation. A future major-version bump will update it to be consistent with other feature-rich implementations of the Fetch API which are used elsewhere in the Apollo Server stack where we use [`make-fetch-happen`](https://npm.im/make-fetch-happen). In all likelihood, `ApolloGateway` will pass its own `fetcher` to the `RemoteGraphQLDataSource` during service initialization. ## 0.16.0 diff --git a/gateway-js/src/datasources/RemoteGraphQLDataSource.ts b/gateway-js/src/datasources/RemoteGraphQLDataSource.ts index feffde81b2..700e78e2f4 100644 --- a/gateway-js/src/datasources/RemoteGraphQLDataSource.ts +++ b/gateway-js/src/datasources/RemoteGraphQLDataSource.ts @@ -20,6 +20,8 @@ import { GraphQLDataSource } from './types'; import createSHA from 'apollo-server-core/dist/utils/createSHA'; export class RemoteGraphQLDataSource = Record> implements GraphQLDataSource { + fetcher: typeof fetch = fetch; + constructor( config?: Partial> & object & @@ -144,7 +146,8 @@ export class RemoteGraphQLDataSource = Reco }); try { - const httpResponse = await fetch(httpRequest); + // Use our local `fetcher` to allow for fetch injection + const httpResponse = await this.fetcher(httpRequest); if (!httpResponse.ok) { throw await this.errorFromResponse(httpResponse); diff --git a/gateway-js/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts b/gateway-js/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts index ff5309dc00..f81b39afb1 100644 --- a/gateway-js/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts +++ b/gateway-js/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts @@ -9,6 +9,7 @@ import { import { RemoteGraphQLDataSource } from '../RemoteGraphQLDataSource'; import { Headers } from 'apollo-server-env'; import { GraphQLRequestContext } from 'apollo-server-types'; +import { Response } from '../../../../../../apollo-tooling/packages/apollo-env/lib'; beforeEach(() => { fetch.mockReset(); @@ -238,6 +239,29 @@ describe('constructing requests', () => { }); }); +describe('fetcher', () => { + it('uses a custom provided `fetcher`', async () => { + const injectedFetch = fetch.mockJSONResponseOnce({ data: { injected: true } }); + const DataSource = new RemoteGraphQLDataSource({ + url: 'https://api.example.com/foo', + fetcher: injectedFetch, + }); + + const { data } = await DataSource.process({ + request: { + query: '{ me { name } }', + variables: { id: '1' }, + }, + context: {}, + }); + + expect(injectedFetch).toHaveBeenCalled(); + expect(data).toEqual({injected: true}); + + }); + +}); + describe('willSendRequest', () => { it('allows for modifying variables', async () => { const DataSource = new RemoteGraphQLDataSource({ From d409df5ddd13bee0d01ef2dea9fd675c740ba04d Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Wed, 27 May 2020 12:54:20 +0000 Subject: [PATCH 6/7] Update CHANGELOG.md files prior to publishing. Apollo-Orig-Commit-AS: apollographql/apollo-server@bbf3df19b8c4fdb5d4ae5aa9b037c65190217f14 --- federation-js/CHANGELOG.md | 4 ++++ gateway-js/CHANGELOG.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/federation-js/CHANGELOG.md b/federation-js/CHANGELOG.md index de1b2d3c5d..a0dc25f3ae 100644 --- a/federation-js/CHANGELOG.md +++ b/federation-js/CHANGELOG.md @@ -6,6 +6,10 @@ - _Nothing yet! Stay tuned._ +## 0.16.1 + +- Only changes in the similarly versioned `@apollo/gateway` package. + ## 0.16.0 - No changes. This package was major versioned to maintain lockstep versioning with @apollo/gateway. diff --git a/gateway-js/CHANGELOG.md b/gateway-js/CHANGELOG.md index 0ce314f654..4f3fa744a7 100644 --- a/gateway-js/CHANGELOG.md +++ b/gateway-js/CHANGELOG.md @@ -4,6 +4,10 @@ > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section. +- _Nothing yet! Stay tuned!_ + +## 0.16.1 + - __NEW__: Provide the ability to pass a custom `fetcher` during `RemoteGraphQLDataSource` construction to be used when executing operations against downstream services. Providing a custom `fetcher` may be necessary to accommodate more advanced needs, e.g., configuring custom TLS certificates for internal services. [PR #4149](https://github.com/apollographql/apollo-server/pull/4149) The `fetcher` specified should be a compliant implementor of the [Fetch API standard](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This addition compliments, though is still orthognonal to, similar behavior originally introduced in [#3783](https://github.com/apollographql/apollo-server/pull/3783), which allowed customization of the implementation used to fetch _gateway configuration and federated SDL from services_ in managed and unmanaged modes, but didn't affect the communication that takes place during _operation execution_. From c4644fbcb8d1835a8e22c807174d04361dbae0e0 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Wed, 27 May 2020 14:18:05 +0000 Subject: [PATCH 7/7] Release - apollo-cache-control@0.11.0 - apollo-datasource-rest@0.9.2 - apollo-datasource@0.7.1 - apollo-engine-reporting-protobuf@0.5.1 - apollo-engine-reporting@2.0.0 - @apollo/federation@0.16.1 - @apollo/gateway@0.16.1 - apollo-server-azure-functions@2.14.0 - apollo-server-cache-memcached@0.6.5 - apollo-server-cache-redis@1.2.1 - apollo-server-cloud-functions@2.14.0 - apollo-server-cloudflare@2.14.0 - apollo-server-core@2.14.0 - apollo-server-env@2.4.4 - apollo-server-express@2.14.0 - apollo-server-fastify@2.14.0 - apollo-server-hapi@2.14.0 - apollo-server-integration-testsuite@2.14.0 - apollo-server-koa@2.14.0 - apollo-server-lambda@2.14.0 - apollo-server-micro@2.14.0 - apollo-server-plugin-base@0.9.0 - apollo-server-plugin-operation-registry@0.3.2 - apollo-server-plugin-response-cache@0.5.2 - apollo-server-testing@2.14.0 - apollo-server-types@0.5.0 - apollo-server@2.14.0 - apollo-tracing@0.11.0 - graphql-extensions@0.12.2 Apollo-Orig-Commit-AS: apollographql/apollo-server@d159e320879f594ba2d04036e3e1aa0653ff164d --- federation-js/package.json | 2 +- gateway-js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/federation-js/package.json b/federation-js/package.json index 520e31a6d7..f978561161 100644 --- a/federation-js/package.json +++ b/federation-js/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/federation", - "version": "0.16.1-alpha.0", + "version": "0.16.1", "description": "Apollo Federation Utilities", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/gateway-js/package.json b/gateway-js/package.json index 8d9088496e..ffa8c1c9b7 100644 --- a/gateway-js/package.json +++ b/gateway-js/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/gateway", - "version": "0.16.1-alpha.2", + "version": "0.16.1", "description": "Apollo Gateway", "author": "opensource@apollographql.com", "main": "dist/index.js",