Skip to content

Commit 48495ac

Browse files
committed
add gzip compression
1 parent 835e455 commit 48495ac

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

packages/plugins/apollo-usage-report/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
},
5050
"devDependencies": {
5151
"@envelop/on-resolve": "^5.1.3",
52-
"@whatwg-node/fetch": "^0.10.6",
5352
"graphql": "16.10.0",
5453
"graphql-yoga": "workspace:*"
5554
},

packages/plugins/apollo-usage-report/src/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,7 @@ export function useApolloUsageReport(options: ApolloUsageReportOptions = {}): Pl
216216
const tracesPerQuery = tracesPerSchema[schemaId]!;
217217
const agentVersion = options.agentVersion || `graphql-yoga@${yoga.version}`;
218218
serverContext.waitUntil(
219-
sendTrace(
220-
options,
221-
logger,
222-
yoga.fetchAPI.fetch,
223-
schemaId,
224-
tracesPerQuery,
225-
agentVersion,
226-
),
219+
sendTrace(options, logger, yoga.fetchAPI, schemaId, tracesPerQuery, agentVersion),
227220
);
228221
}
229222
},
@@ -259,7 +252,7 @@ export function hashSHA256(
259252
function sendTrace(
260253
options: ApolloUsageReportOptions,
261254
logger: YogaLogger,
262-
fetch: FetchAPI['fetch'],
255+
{ fetch, CompressionStream }: FetchAPI,
263256
schemaId: string,
264257
tracesPerQuery: Report['tracesPerQuery'],
265258
agentVersion: string,
@@ -270,7 +263,7 @@ function sendTrace(
270263
endpoint = DEFAULT_REPORTING_ENDPOINT,
271264
} = options;
272265

273-
const body = Report.encode({
266+
const report = Report.encode({
274267
header: {
275268
agentVersion,
276269
graphRef,
@@ -279,19 +272,26 @@ function sendTrace(
279272
operationCount: 1,
280273
tracesPerQuery,
281274
}).finish();
275+
282276
return handleMaybePromise(
283-
() =>
284-
fetch(endpoint, {
277+
() => {
278+
return fetch(endpoint, {
285279
method: 'POST',
286280
headers: {
287281
'content-type': 'application/protobuf',
282+
'content-encoding': 'gzip',
288283
// The presence of the api key is already checked at Yoga initialization time
289-
290284
'x-api-key': apiKey!,
291285
accept: 'application/json',
292286
},
293-
body,
294-
}),
287+
body: new ReadableStream({
288+
start(controller) {
289+
controller.enqueue(report);
290+
controller.close();
291+
},
292+
}).pipeThrough(new CompressionStream('gzip')),
293+
});
294+
},
295295
response =>
296296
handleMaybePromise(
297297
() => response.text(),

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)