Skip to content

Commit

Permalink
graphql-http audit url option can be a function (#7180)
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Nov 21, 2022
1 parent 8cff60a commit a20c2cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/integration-testsuite/package.json
Expand Up @@ -36,7 +36,7 @@
"@josephg/resolvable": "^1.0.1",
"body-parser": "^1.20.0",
"express": "^4.18.1",
"graphql-http": "1.7.2",
"graphql-http": "1.8.0",
"graphql-tag": "^2.12.6",
"loglevel": "^1.8.0",
"node-fetch": "^2.6.7",
Expand Down
19 changes: 5 additions & 14 deletions packages/integration-testsuite/src/httpSpecTests.ts
Expand Up @@ -3,7 +3,7 @@ import type {
CreateServerForIntegrationTestsResult,
} from './index.js';
import { afterAll, beforeAll, describe, test } from '@jest/globals';
import { ServerAuditOptions, serverAudits } from 'graphql-http';
import { serverAudits } from 'graphql-http';
import fetch from 'node-fetch';

export function defineIntegrationTestSuiteHttpSpecTests(
Expand All @@ -12,15 +12,6 @@ export function defineIntegrationTestSuiteHttpSpecTests(
describe('httpSpecTests.ts', () => {
let createServerResult: CreateServerForIntegrationTestsResult | null = null;

const serverAuditOptions: ServerAuditOptions = {
// We don't actually have access to the URL when we need to call
// serverAudits. Fortunately it's not actually read until the tests are
// run, so we can just pass some garbage and overwrite it.
// See https://github.com/graphql/graphql-http/issues/24
url: 'http://should-not-happen.invalid',
fetchFn: fetch,
};

beforeAll(async () => {
createServerResult = await createServer({
// Any schema will do (the tests just run `{__typename}`).
Expand All @@ -29,17 +20,17 @@ export function defineIntegrationTestSuiteHttpSpecTests(
// with GETs. We could override `fetchFn` to add it but this seems simple enough.
csrfPrevention: false,
});
// Until https://github.com/graphql/graphql-http/issues/24 is addressed,
// this hack happens to work.
serverAuditOptions.url = createServerResult.url;
});

afterAll(async () => {
await createServerResult?.server.stop();
await createServerResult?.extraCleanup?.();
});

for (const audit of serverAudits(serverAuditOptions)) {
for (const audit of serverAudits({
url: () => createServerResult!.url,
fetchFn: fetch,
})) {
test(audit.name, async () => {
const result = await audit.fn();

Expand Down

0 comments on commit a20c2cc

Please sign in to comment.