Skip to content

Commit bba81de

Browse files
authored
fix: missing client info reporting with response cache (#6473)
1 parent 4d3d6fc commit bba81de

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

.changeset/three-stingrays-do.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-hive/yoga': patch
3+
---
4+
5+
Correctly extract client information when using the response cache plugin.
6+
7+
The client information was not reported for GraphQL responses served from the response cache plugin.

packages/libraries/yoga/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export function useHive(clientOrOptions: HiveClient | HivePluginOptions): Plugin
161161
schema: latestSchema,
162162
variableValues: record.paramsArgs.variables,
163163
operationName: record.paramsArgs.operationName,
164+
contextValue: serverContext,
164165
},
165166
result,
166167
record.experimental__documentId,

packages/libraries/yoga/tests/yoga.spec.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,22 +372,16 @@ test('reports usage', async ({ expect }) => {
372372

373373
test('reports usage with response cache', async ({ expect }) => {
374374
let usageCount = 0;
375+
const results: Array<Record<string, any>> = [];
375376
const graphqlScope = nock('http://localhost')
376377
.post('/usage', body => {
377378
usageCount++;
378-
379-
expect(body.map).toEqual({
380-
f25063b60ab942d0c0d14cdd9cd3172de2e7ebc4: {
381-
fields: ['Query.hi'],
382-
operation: '{hi}',
383-
operationName: 'anonymous',
384-
},
385-
});
386-
379+
results.push(body);
387380
return true;
388381
})
389382
.thrice()
390383
.reply(200);
384+
391385
const yoga = createYoga({
392386
schema: createSchema({
393387
typeDefs: /* GraphQL */ `
@@ -458,6 +452,23 @@ test('reports usage with response cache', async ({ expect }) => {
458452
});
459453
graphqlScope.done();
460454
expect(usageCount).toBe(3);
455+
456+
for (const body of results) {
457+
expect(body.operations[0].metadata).toEqual({
458+
client: {
459+
name: 'brrr',
460+
version: '1',
461+
},
462+
});
463+
464+
expect(body.map).toEqual({
465+
f25063b60ab942d0c0d14cdd9cd3172de2e7ebc4: {
466+
fields: ['Query.hi'],
467+
operation: '{hi}',
468+
operationName: 'anonymous',
469+
},
470+
});
471+
}
461472
});
462473

463474
test('does not report usage for operation that does not pass validation', async ({ expect }) => {
@@ -1107,10 +1118,10 @@ describe('subscription usage reporting', () => {
11071118
expect(res.status).toBe(200);
11081119
expect(await res.text()).toMatchInlineSnapshot(`
11091120
:
1110-
1121+
11111122
event: next
11121123
data: {"errors":[{"message":"Unexpected error.","locations":[{"line":1,"column":1}],"extensions":{"unexpected":true}}]}
1113-
1124+
11141125
event: complete
11151126
data:
11161127
`);

0 commit comments

Comments
 (0)