Skip to content

Commit 652b7fe

Browse files
committed
Add benchmarks for GQL and SDL validation
1 parent cb5d725 commit 652b7fe

9 files changed

+62
-20
lines changed

resources/benchmark.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ function prepareRevision(revision) {
5353
execSync(`git archive "${hash}" | tar -xC "${dir}"`);
5454
execSync('yarn install', { cwd: dir });
5555
}
56+
5657
for (const file of findFiles(LOCAL_DIR('src'), '*/__tests__/*')) {
5758
const from = LOCAL_DIR('src', file);
5859
const to = path.join(dir, 'src', file);
5960
fs.copyFileSync(from, to);
6061
}
61-
execSync(`yarn run ${BUILD_CMD}`, { cwd: dir });
62+
execSync(`cp -R src/__fixtures__ ${dir}/src/__fixtures__`);
6263

64+
execSync(`yarn run ${BUILD_CMD}`, { cwd: dir });
6365
return path.join(dir, 'dist');
6466
}
6567
}

src/__fixtures__/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { join } from 'path';
2+
import { readFileSync } from 'fs';
3+
4+
function readLocalFile(filename) {
5+
return readFileSync(join(__dirname, filename), 'utf8');
6+
}
7+
8+
export const bigSchemaSDL = readLocalFile('github-schema.graphql');
9+
export const bigSchemaIntrospectionResult = JSON.parse(
10+
readLocalFile('github-schema.json'),
11+
);

src/utilities/__tests__/buildASTSchema-benchmark.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import { join } from 'path';
9-
import { readFileSync } from 'fs';
8+
import { bigSchemaSDL } from '../../__fixtures__';
9+
1010
import { parse } from '../../';
1111
import { buildASTSchema } from '../buildASTSchema';
1212

13-
const schemaAST = parse(
14-
readFileSync(join(__dirname, 'github-schema.graphql'), 'utf8'),
15-
);
13+
const schemaAST = parse(bigSchemaSDL);
1614

1715
export const name = 'Build Schema from AST';
1816
export function measure() {

src/utilities/__tests__/buildClientSchema-benchmark.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import { join } from 'path';
9-
import { readFileSync } from 'fs';
10-
import { buildClientSchema } from '../buildClientSchema';
8+
import { bigSchemaIntrospectionResult } from '../../__fixtures__';
119

12-
const schemaJSON = JSON.parse(
13-
readFileSync(join(__dirname, 'github-schema.json'), 'utf8'),
14-
);
10+
import { buildClientSchema } from '../buildClientSchema';
1511

1612
export const name = 'Build Schema from Introspection';
1713
export function measure() {
18-
buildClientSchema(schemaJSON.data);
14+
buildClientSchema(bigSchemaIntrospectionResult.data);
1915
}

src/utilities/__tests__/introspectionFromSchema-benchmark.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import { join } from 'path';
9-
import { readFileSync } from 'fs';
8+
import { bigSchemaSDL } from '../../__fixtures__';
9+
1010
import { execute, parse } from '../../';
11-
import { buildASTSchema } from '../buildASTSchema';
11+
import { buildSchema } from '../buildASTSchema';
1212
import { getIntrospectionQuery } from '../introspectionQuery';
1313

1414
const queryAST = parse(getIntrospectionQuery());
15-
const schema = buildASTSchema(
16-
parse(readFileSync(join(__dirname, 'github-schema.graphql'), 'utf8')),
17-
{ assumeValid: true },
18-
);
15+
const schema = buildSchema(bigSchemaSDL, { assumeValid: true });
1916

2017
export const name = 'Execute Introspection Query';
2118
export function measure() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2018-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { bigSchemaSDL } from '../../__fixtures__';
9+
10+
import { parse, getIntrospectionQuery, buildSchema } from '../../';
11+
import { validate } from '../validate';
12+
13+
const schema = buildSchema(bigSchemaSDL, { assumeValid: true });
14+
const queryAST = parse(getIntrospectionQuery());
15+
16+
export const name = 'Validate Introspection Query';
17+
export function measure() {
18+
validate(schema, queryAST);
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2018-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { bigSchemaSDL } from '../../__fixtures__';
9+
10+
import { parse } from '../../';
11+
import { validateSDL } from '../validate';
12+
13+
const sdlAST = parse(bigSchemaSDL);
14+
15+
export const name = 'Validate SDL Document';
16+
export function measure() {
17+
validateSDL(sdlAST);
18+
}
19+

0 commit comments

Comments
 (0)