fix: client info sanitisation (#4932)

This commit is contained in:
Laurin Quast 2024-06-06 14:32:39 +02:00 committed by GitHub
parent 8065e48bce
commit cbc836488b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View file

@ -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.

View file

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