Skip to content

Commit

Permalink
Add benchmarks for GQL and SDL validation
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Aug 15, 2018
1 parent cb5d725 commit 652b7fe
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 20 deletions.
4 changes: 3 additions & 1 deletion resources/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ function prepareRevision(revision) {
execSync(`git archive "${hash}" | tar -xC "${dir}"`);
execSync('yarn install', { cwd: dir });
}

for (const file of findFiles(LOCAL_DIR('src'), '*/__tests__/*')) {
const from = LOCAL_DIR('src', file);
const to = path.join(dir, 'src', file);
fs.copyFileSync(from, to);
}
execSync(`yarn run ${BUILD_CMD}`, { cwd: dir });
execSync(`cp -R src/__fixtures__ ${dir}/src/__fixtures__`);

execSync(`yarn run ${BUILD_CMD}`, { cwd: dir });
return path.join(dir, 'dist');
}
}
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);
}
19 changes: 19 additions & 0 deletions src/validation/__tests__/validateSDL-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 } from '../../';
import { validateSDL } from '../validate';

const sdlAST = parse(bigSchemaSDL);

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

0 comments on commit 652b7fe

Please sign in to comment.