Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks for GQL and SDL validation #1471

Merged
merged 1 commit into from
Aug 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__" &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjmahone This makes this PR independent and can be reviewed without #1470

(cd "${dir}" && yarn run ${BUILD_CMD})
`);
}
Expand Down
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);
}