Skip to content

Commit f68e8e2

Browse files
Add benchmarks for GQL and SDL validation (#1471)
1 parent afe6d34 commit f68e8e2

9 files changed

+59
-19
lines changed

resources/benchmark.js

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function prepareRevision(revision) {
5656
for file in $(cd "${LOCAL_DIR}src"; find . -path '*/__tests__/*');
5757
do cp "${LOCAL_DIR}src/$file" "${dir}/src/$file";
5858
done &&
59+
cp -R "${LOCAL_DIR}/src/__fixtures__" "${dir}/src/__fixtures__" &&
5960
(cd "${dir}" && yarn run ${BUILD_CMD})
6061
`);
6162
}

src/__fixtures__/index.js

+11
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

+3-5
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

+3-7
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

+4-7
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() {
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

0 commit comments

Comments
 (0)