From 0a128d1b0ebad8281a7e6401da3b25c628c5a033 Mon Sep 17 00:00:00 2001 From: Max Kurapov Date: Fri, 13 Dec 2024 14:57:57 +0100 Subject: [PATCH] test(backend): sign GraphQL requests in test environment --- packages/backend/src/tests/app.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/tests/app.ts b/packages/backend/src/tests/app.ts index cbe82b4704..50e0b22014 100644 --- a/packages/backend/src/tests/app.ts +++ b/packages/backend/src/tests/app.ts @@ -12,8 +12,9 @@ import { import { setContext } from '@apollo/client/link/context' import { start, gracefulShutdown } from '..' import { onError } from '@apollo/client/link/error' - +import { print } from 'graphql/language/printer' import { App, AppServices } from '../app' +import { generateApiSignature } from './apiSignature' export const testAccessToken = 'test-app-access' @@ -76,10 +77,20 @@ export const createTestApp = async ( }) } }) - const authLink = setContext((_, { headers }) => { + const authLink = setContext((request, { headers }) => { + const requestBody = { + variables: request.variables, + operationName: request.operationName, + query: print(request.query) + } return { headers: { - ...headers + ...headers, + signature: generateApiSignature( + config.adminApiSecret, + config.adminApiSignatureVersion, + requestBody + ) } } })