Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use Promise constructor to wrap builtin gzip #7229

Merged
merged 2 commits into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-schools-glow.md
@@ -0,0 +1,5 @@
---
'@apollo/server': patch
---

Improve compatibility with Cloudflare workers by avoiding the use of the Node `util` package. This change is intended to be a no-op.
9 changes: 5 additions & 4 deletions packages/server/src/plugin/usageReporting/plugin.ts
Expand Up @@ -11,7 +11,6 @@ import type LRUCache from 'lru-cache';
import { AbortController } from 'node-abort-controller';
import fetch from 'node-fetch';
import os from 'os';
import { promisify } from 'util';
import { gzip } from 'zlib';
import type {
ApolloServerPlugin,
Expand Down Expand Up @@ -41,8 +40,6 @@ import { computeCoreSchemaHash } from '../../utils/computeCoreSchemaHash.js';
import type { HeaderMap } from '../../utils/HeaderMap.js';
import { schemaIsSubgraph } from '../schemaIsSubgraph.js';

const gzipPromise = promisify(gzip);

const reportHeaderDefaults = {
hostname: os.hostname(),
agentVersion: `@apollo/server@${packageVersion}`,
Expand Down Expand Up @@ -305,7 +302,11 @@ export function ApolloServerPluginUsageReporting<TContext extends BaseContext>(
);
}

const compressed = await gzipPromise(message);
const compressed = await new Promise<Buffer>((resolve, reject) => {
gzip(message!, (error, result) => {
error ? reject(error) : resolve(result);
});
});
// Let the uncompressed message be garbage collected (helpful if the
// HTTP request is slow).
message = null;
Expand Down