From cbc836488b4acfb618fd877005ecf0126f1706b6 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Thu, 6 Jun 2024 14:32:39 +0200 Subject: [PATCH] fix: client info sanitisation (#4932) --- .changeset/clean-cameras-compete.md | 6 ++++++ packages/libraries/core/src/client/usage.ts | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 .changeset/clean-cameras-compete.md diff --git a/.changeset/clean-cameras-compete.md b/.changeset/clean-cameras-compete.md new file mode 100644 index 000000000..f1b7796e4 --- /dev/null +++ b/.changeset/clean-cameras-compete.md @@ -0,0 +1,6 @@ +--- +'@graphql-hive/core': patch +--- + +Prevent failing usage reporting when returning an object with additional properties aside from +`name` and `version` from the client info object/factory function. diff --git a/packages/libraries/core/src/client/usage.ts b/packages/libraries/core/src/client/usage.ts index 460508984..70b2d2229 100644 --- a/packages/libraries/core/src/client/usage.ts +++ b/packages/libraries/core/src/client/usage.ts @@ -215,11 +215,12 @@ export function createUsage(pluginOptions: HivePluginOptions): UsageCollector { errors, }, // TODO: operationHash is ready to accept hashes of persisted operations - client: + client: pickClientInfoProperties( typeof args.contextValue !== 'undefined' && - typeof options.clientInfo !== 'undefined' + typeof options.clientInfo !== 'undefined' ? options.clientInfo(args.contextValue) : createDefaultClientInfo()(args.contextValue), + ), }, }; }), @@ -501,3 +502,13 @@ function createDefaultClientInfo( return null; }; } + +function pickClientInfoProperties(info: null | undefined | ClientInfo): null | ClientInfo { + if (!info) { + return null; + } + return { + name: info.name, + version: info.version, + }; +}