Skip to content

Commit

Permalink
Add benchmarks for GQL and SDL validation (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Aug 25, 2018
1 parent afe6d34 commit f68e8e2
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions resources/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function prepareRevision(revision) {
for file in $(cd "${LOCAL_DIR}src"; find . -path '*/__tests__/*');
do cp "${LOCAL_DIR}src/$file" "${dir}/src/$file";
done &&
cp -R "${LOCAL_DIR}/src/__fixtures__" "${dir}/src/__fixtures__" &&
(cd "${dir}" && yarn run ${BUILD_CMD})
`);
}
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions src/__fixtures__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { join } from 'path';
import { readFileSync } from 'fs';

function readLocalFile(filename) {
return readFileSync(join(__dirname, filename), 'utf8');
}

export const bigSchemaSDL = readLocalFile('github-schema.graphql');
export const bigSchemaIntrospectionResult = JSON.parse(
readLocalFile('github-schema.json'),
);
8 changes: 3 additions & 5 deletions src/utilities/__tests__/buildASTSchema-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import { join } from 'path';
import { readFileSync } from 'fs';
import { bigSchemaSDL } from '../../__fixtures__';

import { parse } from '../../';
import { buildASTSchema } from '../buildASTSchema';

const schemaAST = parse(
readFileSync(join(__dirname, 'github-schema.graphql'), 'utf8'),
);
const schemaAST = parse(bigSchemaSDL);

export const name = 'Build Schema from AST';
export function measure() {
Expand Down
10 changes: 3 additions & 7 deletions src/utilities/__tests__/buildClientSchema-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import { join } from 'path';
import { readFileSync } from 'fs';
import { buildClientSchema } from '../buildClientSchema';
import { bigSchemaIntrospectionResult } from '../../__fixtures__';

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

export const name = 'Build Schema from Introspection';
export function measure() {
buildClientSchema(schemaJSON.data);
buildClientSchema(bigSchemaIntrospectionResult.data);
}
11 changes: 4 additions & 7 deletions src/utilities/__tests__/introspectionFromSchema-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

import { join } from 'path';
import { readFileSync } from 'fs';
import { bigSchemaSDL } from '../../__fixtures__';

import { execute, parse } from '../../';
import { buildASTSchema } from '../buildASTSchema';
import { buildSchema } from '../buildASTSchema';
import { getIntrospectionQuery } from '../introspectionQuery';

const queryAST = parse(getIntrospectionQuery());
const schema = buildASTSchema(
parse(readFileSync(join(__dirname, 'github-schema.graphql'), 'utf8')),
{ assumeValid: true },
);
const schema = buildSchema(bigSchemaSDL, { assumeValid: true });

export const name = 'Execute Introspection Query';
export function measure() {
Expand Down
19 changes: 19 additions & 0 deletions src/validation/__tests__/validateGQL-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { bigSchemaSDL } from '../../__fixtures__';

import { parse, getIntrospectionQuery, buildSchema } from '../../';
import { validate } from '../validate';

const schema = buildSchema(bigSchemaSDL, { assumeValid: true });
const queryAST = parse(getIntrospectionQuery());

export const name = 'Validate Introspection Query';
export function measure() {
validate(schema, queryAST);
}
18 changes: 18 additions & 0 deletions src/validation/__tests__/validateSDL-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { bigSchemaSDL } from '../../__fixtures__';

import { parse } from '../../';
import { validateSDL } from '../validate';

const sdlAST = parse(bigSchemaSDL);

export const name = 'Validate SDL Document';
export function measure() {
validateSDL(sdlAST);
}

0 comments on commit f68e8e2

Please sign in to comment.