Skip to content
Draft
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
20 changes: 20 additions & 0 deletions benchmark/validateWithRulesExecutable-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
import { getIntrospectionQuery } from 'graphql/utilities/getIntrospectionQuery.js';
import * as GraphQLValidation from 'graphql/validation/index.js';
import { validate } from 'graphql/validation/validate.js';

import { bigSchemaSDL } from './fixtures.js';

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

export const benchmark = {
name: 'Validate With Rules - Executable Document',
measure: () =>
validateWithRules?.({
documentAST: queryAST,
schema,
}) ?? validate(schema, queryAST),
};
31 changes: 31 additions & 0 deletions benchmark/validateWithRulesExecutableSDL-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
import { extendSchema } from 'graphql/utilities/extendSchema.js';
import { getIntrospectionQuery } from 'graphql/utilities/getIntrospectionQuery.js';
import * as GraphQLValidation from 'graphql/validation/index.js';
import { validate, validateSDL } from 'graphql/validation/validate.js';

import { bigSchemaSDL } from './fixtures.js';

const validateWithRules = GraphQLValidation.validateWithRules;
const schema = buildSchema(bigSchemaSDL, { assumeValid: true });
const extensionSDL = 'extend type Query { _benchmarkAddedField: String }';
const extensionAST = parse(extensionSDL);
const extendedSchema = extendSchema(schema, extensionAST);
const queryAST = parse(getIntrospectionQuery());
const documentAST = {
...extensionAST,
definitions: extensionAST.definitions.concat(queryAST.definitions),
};

export const benchmark = {
name: 'Validate With Rules - Executable Document With SDL',
measure: () =>
validateWithRules?.({
documentAST,
schema,
}) ??
validateSDL(extensionAST, schema).concat(
validate(extendedSchema, queryAST),
),
};
16 changes: 16 additions & 0 deletions benchmark/validateWithRulesGraphQLSchema-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { validateSchema } from 'graphql/type/validate.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
import * as GraphQLValidation from 'graphql/validation/index.js';

import { bigSchemaSDL } from './fixtures.js';

const validateWithRules = GraphQLValidation.validateWithRules;
const schema = buildSchema(bigSchemaSDL);

export const benchmark = {
name: 'Validate With Rules - GraphQLSchema',
measure: () => {
schema.__validationErrors = undefined;
return validateWithRules?.({ schema }) ?? validateSchema(schema);
},
};
16 changes: 16 additions & 0 deletions benchmark/validateWithRulesSDL-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { parse } from 'graphql/language/parser.js';
import * as GraphQLValidation from 'graphql/validation/index.js';
import { validateSDL } from 'graphql/validation/validate.js';

import { bigSchemaSDL } from './fixtures.js';

const validateWithRules = GraphQLValidation.validateWithRules;
const documentAST = parse(bigSchemaSDL);

export const benchmark = {
name: 'Validate With Rules - SDL Document',
measure: () =>
validateWithRules?.({
documentAST,
}) ?? validateSDL(documentAST),
};
24 changes: 24 additions & 0 deletions benchmark/validateWithRulesSDLAndSchema-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { parse } from 'graphql/language/parser.js';
import { validateSchema } from 'graphql/type/validate.js';
import { buildASTSchema } from 'graphql/utilities/buildASTSchema.js';
import * as GraphQLValidation from 'graphql/validation/index.js';
import { validateSDL } from 'graphql/validation/validate.js';

import { bigSchemaSDL } from './fixtures.js';

const validateWithRules = GraphQLValidation.validateWithRules;
const documentAST = parse(bigSchemaSDL);

export const benchmark = {
name: 'Validate With Rules - SDL Document And Schema',
measure: () =>
(validateWithRules?.({
documentAST,
}) &&
buildASTSchema(documentAST, {
assumeValidSDL: true,
assumeValid: true,
})) ??
(validateSDL(documentAST) &&
validateSchema(buildASTSchema(documentAST, { assumeValidSDL: true }))),
};
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,12 @@ export type {
export {
validate,
ValidationContext,
validateWithRules,
// All validation rules in the GraphQL Specification.
specifiedRules,
recommendedRules,
specifiedASTValidationRules,
specifiedTypeSystemValidationRules,
// Individual validation rules.
DeferStreamDirectiveLabelRule,
DeferStreamDirectiveOnRootFieldRule,
Expand Down Expand Up @@ -481,7 +484,11 @@ export {
NoSchemaIntrospectionCustomRule,
} from './validation/index.ts';

export type { ValidationOptions, ValidationRule } from './validation/index.ts';
export type {
ValidateWithRulesOptions,
ValidationOptions,
ValidationRule,
} from './validation/index.ts';

// Create, format, and print GraphQL errors.
export { GraphQLError, syntaxError, locatedError } from './error/index.ts';
Expand Down
Loading
Loading