Skip to content

Commit 43920cd

Browse files
authored
fix(client): send the correct version for integration packages (#7253)
1 parent 2ea6db6 commit 43920cd

File tree

13 files changed

+53
-10
lines changed

13 files changed

+53
-10
lines changed

.changeset/fifty-shirts-strive.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-hive/envelop': patch
3+
'@graphql-hive/yoga': patch
4+
'@graphql-hive/apollo': patch
5+
---
6+
7+
Send correct version of the client packages, previously they were sending the version of `@graphql-hive/core` package.

.changeset/five-spiders-serve.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@graphql-hive/core': patch
3+
---
4+
5+
Allow to provide `version` to `AgentOptions` in Hive Client integrations.
6+
7+
```ts
8+
createHive({
9+
agent: {
10+
name: 'my-custom-agent',
11+
version: '1.2.3', // new field
12+
},
13+
})
14+
```
15+
16+
Currently you can provide `name` but not `version`. This change allows to provide both `name` and `version` to better identify the clients connecting to Hive Console.
17+
Previously the dependent libraries like Yoga, Envelop and Hive Gateway integrations were incorrectly sending their names with the version of `@graphql-hive/core` package. Now they will be able to send their own versions.

.changeset/spotty-beans-report.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-hive/core': patch
3+
---
4+
5+
Accept `name` and `version` to `createSupergraphSDLFetcher` to build a more accurate user agent
6+
instead of passing `hive-client` with `@graphql-hive/core`'s version

packages/libraries/apollo/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
isHiveClient,
1010
SupergraphSDLFetcherOptions,
1111
} from '@graphql-hive/core';
12+
import { version } from './version.js';
1213

1314
export {
1415
atLeastOnceSampler,
@@ -78,6 +79,7 @@ export function createHive(clientOrOptions: HivePluginOptions) {
7879
...clientOrOptions,
7980
agent: {
8081
name: 'hive-client-yoga',
82+
version,
8183
...clientOrOptions.agent,
8284
},
8385
});

packages/libraries/core/src/client/agent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type ReadOnlyResponse = Pick<Response, 'status' | 'text' | 'json' | 'statusText'
77
export interface AgentOptions {
88
enabled?: boolean;
99
name?: string;
10+
version?: string;
1011
/**
1112
* Hive endpoint or proxy
1213
*/
@@ -76,6 +77,7 @@ export function createAgent<TEvent>(
7677
maxSize: 25,
7778
logger: console,
7879
name: 'hive-client',
80+
version,
7981
...pluginOptions,
8082
};
8183

@@ -164,7 +166,7 @@ export function createAgent<TEvent>(
164166
accept: 'application/json',
165167
'content-type': 'application/json',
166168
Authorization: `Bearer ${options.token}`,
167-
'User-Agent': `${options.name}/${version}`,
169+
'User-Agent': `${options.name}/${options.version}`,
168170
...headers(),
169171
},
170172
timeout: options.timeout,

packages/libraries/core/src/client/client.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export function createHive(options: HivePluginOptions): HiveClient {
110110

111111
infoLogger.info('Fetching token details...');
112112

113+
const clientVersionForDetails = options.agent?.version || version;
113114
const response = await http.post(
114115
endpoint,
115116
JSON.stringify({
@@ -120,9 +121,9 @@ export function createHive(options: HivePluginOptions): HiveClient {
120121
headers: {
121122
'content-type': 'application/json',
122123
Authorization: `Bearer ${options.token}`,
123-
'user-agent': `hive-client/${version}`,
124-
'graphql-client-name': 'Hive Client',
125-
'graphql-client-version': version,
124+
'user-agent': `${options.agent?.name || 'hive-client'}/${clientVersionForDetails}`,
125+
'graphql-client-name': `${options.agent?.name || 'Hive Client'}`,
126+
'graphql-client-version': clientVersionForDetails,
126127
},
127128
timeout: 30_000,
128129
fetchImplementation: options?.agent?.fetch,

packages/libraries/core/src/client/gateways.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function createFetcher(options: SchemaFetcherOptions & ServicesFetcherOptions) {
2727
} = {
2828
'X-Hive-CDN-Key': options.key,
2929
accept: 'application/json',
30-
'User-Agent': `hive-client/${version}`,
30+
'User-Agent': `${options?.name || 'hive-client'}/${options?.version || version}`,
3131
};
3232

3333
if (cacheETag) {

packages/libraries/core/src/client/reporting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export function createReporting(pluginOptions: HivePluginOptions): SchemaReporte
7575
}),
7676
{
7777
headers: {
78-
'graphql-client-name': 'Hive Client',
79-
'graphql-client-version': version,
78+
'graphql-client-name': pluginOptions.agent?.name ?? 'Hive Client',
79+
'graphql-client-version': pluginOptions.agent?.version ?? version,
8080
authorization: `Bearer ${token}`,
8181
'content-type': 'application/json',
8282
},

packages/libraries/core/src/client/supergraph.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface SupergraphSDLFetcherOptions {
88
key: string;
99
logger?: Logger;
1010
fetchImplementation?: typeof fetch;
11+
name?: string;
12+
version?: string;
1113
}
1214

1315
export function createSupergraphSDLFetcher(options: SupergraphSDLFetcherOptions) {
@@ -25,7 +27,7 @@ export function createSupergraphSDLFetcher(options: SupergraphSDLFetcherOptions)
2527
[key: string]: string;
2628
} = {
2729
'X-Hive-CDN-Key': options.key,
28-
'User-Agent': `hive-client/${version}`,
30+
'User-Agent': `${options?.name || 'hive-client'}/${options?.version || version}`,
2931
};
3032

3133
if (cacheETag) {

packages/libraries/core/src/client/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ export interface SchemaFetcherOptions {
270270
endpoint: string;
271271
key: string;
272272
logger?: Logger;
273+
name?: string;
274+
version?: string;
273275
}
274276

275277
export interface ServicesFetcherOptions {

0 commit comments

Comments
 (0)