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, + }; +}