Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/three-stingrays-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-hive/yoga': patch
---

Correctly extract client information when using the response cache plugin.

The client information was not reported for GraphQL responses served from the response cache plugin.
1 change: 1 addition & 0 deletions packages/libraries/yoga/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function useHive(clientOrOptions: HiveClient | HivePluginOptions): Plugin
schema: latestSchema,
variableValues: record.paramsArgs.variables,
operationName: record.paramsArgs.operationName,
contextValue: serverContext,
},
result,
record.experimental__documentId,
Expand Down
33 changes: 22 additions & 11 deletions packages/libraries/yoga/tests/yoga.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,16 @@ test('reports usage', async ({ expect }) => {

test('reports usage with response cache', async ({ expect }) => {
let usageCount = 0;
const results: Array<Record<string, any>> = [];
const graphqlScope = nock('http://localhost')
.post('/usage', body => {
usageCount++;

expect(body.map).toEqual({
f25063b60ab942d0c0d14cdd9cd3172de2e7ebc4: {
fields: ['Query.hi'],
operation: '{hi}',
operationName: 'anonymous',
},
});

results.push(body);
return true;
})
.thrice()
.reply(200);

const yoga = createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
Expand Down Expand Up @@ -458,6 +452,23 @@ test('reports usage with response cache', async ({ expect }) => {
});
graphqlScope.done();
expect(usageCount).toBe(3);

for (const body of results) {
expect(body.operations[0].metadata).toEqual({
client: {
name: 'brrr',
version: '1',
},
});

expect(body.map).toEqual({
f25063b60ab942d0c0d14cdd9cd3172de2e7ebc4: {
fields: ['Query.hi'],
operation: '{hi}',
operationName: 'anonymous',
},
});
}
});

test('does not report usage for operation that does not pass validation', async ({ expect }) => {
Expand Down Expand Up @@ -1107,10 +1118,10 @@ describe('subscription usage reporting', () => {
expect(res.status).toBe(200);
expect(await res.text()).toMatchInlineSnapshot(`
:

event: next
data: {"errors":[{"message":"Unexpected error.","locations":[{"line":1,"column":1}],"extensions":{"unexpected":true}}]}

event: complete
data:
`);
Expand Down
Loading