From b80d75e6485c83be3899143af94a0231d549293f Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Wed, 5 Feb 2025 12:50:28 +0100 Subject: [PATCH 1/3] test: missing client info --- packages/libraries/yoga/tests/yoga.spec.ts | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/libraries/yoga/tests/yoga.spec.ts b/packages/libraries/yoga/tests/yoga.spec.ts index ccf75eae79..90f122642f 100644 --- a/packages/libraries/yoga/tests/yoga.spec.ts +++ b/packages/libraries/yoga/tests/yoga.spec.ts @@ -372,22 +372,16 @@ test('reports usage', async ({ expect }) => { test('reports usage with response cache', async ({ expect }) => { let usageCount = 0; + const results: Array> = []; 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 */ ` @@ -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 }) => { @@ -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: `); From e73c2c78a778305b08fcb7ff310083d07acc7dd3 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Wed, 5 Feb 2025 12:56:45 +0100 Subject: [PATCH 2/3] fix: pass server context to response cache context value for extracting client info --- packages/libraries/yoga/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/libraries/yoga/src/index.ts b/packages/libraries/yoga/src/index.ts index f383c269e6..464b3a257d 100644 --- a/packages/libraries/yoga/src/index.ts +++ b/packages/libraries/yoga/src/index.ts @@ -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, From db4399384f969ef7c1f0b8e736e1119b410d56be Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Wed, 5 Feb 2025 12:58:40 +0100 Subject: [PATCH 3/3] changeset --- .changeset/three-stingrays-do.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/three-stingrays-do.md diff --git a/.changeset/three-stingrays-do.md b/.changeset/three-stingrays-do.md new file mode 100644 index 0000000000..d7c6542623 --- /dev/null +++ b/.changeset/three-stingrays-do.md @@ -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.