diff --git a/.changeset/good-schools-glow.md b/.changeset/good-schools-glow.md new file mode 100644 index 00000000000..abf5305e56b --- /dev/null +++ b/.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. diff --git a/packages/server/src/plugin/usageReporting/plugin.ts b/packages/server/src/plugin/usageReporting/plugin.ts index 834f6276794..9b7824e0ddd 100644 --- a/packages/server/src/plugin/usageReporting/plugin.ts +++ b/packages/server/src/plugin/usageReporting/plugin.ts @@ -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, @@ -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}`, @@ -305,7 +302,11 @@ export function ApolloServerPluginUsageReporting( ); } - const compressed = await gzipPromise(message); + const compressed = await new Promise((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;