Skip to content

Commit 0a128d1

Browse files
committed
test(backend): sign GraphQL requests in test environment
1 parent db5d0e9 commit 0a128d1

File tree

1 file changed

+14
-3
lines changed
  • packages/backend/src/tests

1 file changed

+14
-3
lines changed

packages/backend/src/tests/app.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import {
1212
import { setContext } from '@apollo/client/link/context'
1313
import { start, gracefulShutdown } from '..'
1414
import { onError } from '@apollo/client/link/error'
15-
15+
import { print } from 'graphql/language/printer'
1616
import { App, AppServices } from '../app'
17+
import { generateApiSignature } from './apiSignature'
1718

1819
export const testAccessToken = 'test-app-access'
1920

@@ -76,10 +77,20 @@ export const createTestApp = async (
7677
})
7778
}
7879
})
79-
const authLink = setContext((_, { headers }) => {
80+
const authLink = setContext((request, { headers }) => {
81+
const requestBody = {
82+
variables: request.variables,
83+
operationName: request.operationName,
84+
query: print(request.query)
85+
}
8086
return {
8187
headers: {
82-
...headers
88+
...headers,
89+
signature: generateApiSignature(
90+
config.adminApiSecret,
91+
config.adminApiSignatureVersion,
92+
requestBody
93+
)
8394
}
8495
}
8596
})

0 commit comments

Comments
 (0)