Skip to content

Commit

Permalink
test(backend): sign GraphQL requests in test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurapov committed Dec 13, 2024
1 parent db5d0e9 commit 0a128d1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/backend/src/tests/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
)
}
}
})
Expand Down

0 comments on commit 0a128d1

Please sign in to comment.