Skip to content

Commit

Permalink
feature(apollo-engine-reporting): Add custom http agent support
Browse files Browse the repository at this point in the history
  • Loading branch information
eberhara committed Oct 25, 2018
1 parent c1b0af1 commit bd6f961
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Allow an optional function to resolve the `rootValue`, passing the `DocumentNode` AST to determine the value. [PR #1555](https://github.com/apollographql/apollo-server/pull/1555)
- Follow-up on the work in [PR #1516](https://github.com/apollographql/apollo-server/pull/1516) to also fix missing insertion cursor/caret when a custom GraphQL configuration is specified which doesn't specify its own `cursorShape` property. [PR #1607](https://github.com/apollographql/apollo-server/pull/1607)
- Add support for custom http(s) agent on apollo-engine-reporting to be used on the network requests to apollo-engine endpoint. [PR #1879](https://github.com/apollographql/apollo-server/pull/1879)

### v2.1.0

Expand Down
4 changes: 4 additions & 0 deletions docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ addMockFunctionsToSchema({

The URL of the Engine report ingress server.

* `requestAgent`: `http.Agent | https.Agent | boolean`

HTTP(s) agent to be used on the metrics reporting request to apollo engine endpoint. For more details on the supported configurations, refer to [http.Agent](https://nodejs.org/docs/latest-v10.x/api/http.html#http_class_http_agent) and [https.Agent](https://nodejs.org/docs/latest-v10.x/api/https.html#https_class_https_agent) docs.

* `debugPrintReports`: boolean

If set, prints all reports as JSON when they are sent.
Expand Down
5 changes: 4 additions & 1 deletion packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Trace,
} from 'apollo-engine-reporting-protobuf';

import { fetch, Response } from 'apollo-server-env';
import { fetch, RequestAgent, Response } from 'apollo-server-env';
import retry from 'async-retry';

import { EngineReportingExtension } from './extension';
Expand Down Expand Up @@ -60,6 +60,8 @@ export interface EngineReportingOptions {
endpointUrl?: string;
// If set, prints all reports as JSON when they are sent.
debugPrintReports?: boolean;
// HTTP(s) agent to be used on the fetch call to apollo-engine metrics endpoint
requestAgent?: RequestAgent | boolean;
// Reporting is retried with exponential backoff up to this many times
// (including the original request). Defaults to 5.
maxAttempts?: number;
Expand Down Expand Up @@ -256,6 +258,7 @@ export class EngineReportingAgent<TContext = any> {
'content-encoding': 'gzip',
},
body: compressed,
agent: this.options.requestAgent,
});

if (curResponse.status >= 500 && curResponse.status < 600) {
Expand Down
7 changes: 5 additions & 2 deletions packages/apollo-server-env/src/fetch.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Agent } from 'http';
import { Agent as HttpAgent } from 'http';
import { Agent as HttpsAgent } from 'https';

export declare function fetch(
input?: RequestInfo,
init?: RequestInit,
): Promise<Response>;

export type RequestAgent = HttpAgent | HttpsAgent;

export type RequestInfo = Request | string;

export declare class Headers implements Iterable<[string, string]> {
Expand Down Expand Up @@ -58,7 +61,7 @@ export interface RequestInit {
timeout?: number;
compress?: boolean;
size?: number;
agent?: Agent;
agent?: RequestAgent | boolean;

// Cloudflare Workers accept a `cf` property to control Cloudflare features
// See https://developers.cloudflare.com/workers/reference/cloudflare-features/
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-server-env/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Headers = import('./fetch').Headers;
type HeadersInit = import('./fetch').HeadersInit;
type Body = import('./fetch').Body;
type Request = import('./fetch').Request;
type RequestAgent = import('./fetch').RequestAgent;
type RequestInit = import('./fetch').RequestInit;
type RequestMode = import('./fetch').RequestMode;
type RequestCredentials = import('./fetch').RequestCredentials;
Expand Down

0 comments on commit bd6f961

Please sign in to comment.