Skip to content

Commit

Permalink
introduce simple user provided caches for parse/validate
Browse files Browse the repository at this point in the history
BREAKING CHANGE: parse/validate become potentially async when provided with a cache with an async getter,

Introduces parseSync/validateSync to throw when an async value is returned.

Updates all non-cache tests to use parseSync/validateSync.
  • Loading branch information
yaacovCR committed Nov 5, 2024
1 parent cca3f98 commit 8fee71f
Show file tree
Hide file tree
Showing 61 changed files with 964 additions and 68 deletions.
2 changes: 1 addition & 1 deletion benchmark/buildASTSchema-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { buildASTSchema } from 'graphql/utilities/buildASTSchema.js';

import { bigSchemaSDL } from './fixtures.js';
Expand Down
2 changes: 1 addition & 1 deletion benchmark/introspectionFromSchema-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { executeSync } from 'graphql/execution/execute.js';
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
import { getIntrospectionQuery } from 'graphql/utilities/getIntrospectionQuery.js';

Expand Down
2 changes: 1 addition & 1 deletion benchmark/list-async-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execute } from 'graphql/execution/execute.js';
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';

const schema = buildSchema('type Query { listField: [String] }');
Expand Down
2 changes: 1 addition & 1 deletion benchmark/list-asyncIterable-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execute } from 'graphql/execution/execute.js';
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';

const schema = buildSchema('type Query { listField: [String] }');
Expand Down
2 changes: 1 addition & 1 deletion benchmark/list-sync-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execute } from 'graphql/execution/execute.js';
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';

const schema = buildSchema('type Query { listField: [String] }');
Expand Down
2 changes: 1 addition & 1 deletion benchmark/parser-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { getIntrospectionQuery } from 'graphql/utilities/getIntrospectionQuery.js';

const introspectionQuery = getIntrospectionQuery();
Expand Down
4 changes: 2 additions & 2 deletions benchmark/validateGQL-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
import { getIntrospectionQuery } from 'graphql/utilities/getIntrospectionQuery.js';
import { validate } from 'graphql/validation/validate.js';
import { validateSync as validate } from 'graphql/validation/validate.js';

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

Expand Down
4 changes: 2 additions & 2 deletions benchmark/validateInvalidGQL-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';
import { validate } from 'graphql/validation/validate.js';
import { validateSync as validate } from 'graphql/validation/validate.js';

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

Expand Down
2 changes: 1 addition & 1 deletion benchmark/validateSDL-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { validateSDL } from 'graphql/validation/validate.js';

import { bigSchemaSDL } from './fixtures.js';
Expand Down
2 changes: 1 addition & 1 deletion benchmark/visit-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { visit } from 'graphql/language/visitor.js';

import { bigSchemaSDL } from './fixtures.js';
Expand Down
2 changes: 1 addition & 1 deletion benchmark/visitInParallel-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from 'graphql/language/parser.js';
import { parseSync as parse } from 'graphql/language/parser.js';
import { visit, visitInParallel } from 'graphql/language/visitor.js';

import { bigSchemaSDL } from './fixtures.js';
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/starWarsValidation-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { parse } from '../language/parser.js';
import { parseSync as parse } from '../language/parser.js';
import { Source } from '../language/source.js';

import { validate } from '../validation/validate.js';
import { validateSync as validate } from '../validation/validate.js';

import { StarWarsSchema } from './starWarsSchema.js';

Expand Down
2 changes: 1 addition & 1 deletion src/error/__tests__/GraphQLError-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, it } from 'mocha';
import { dedent } from '../../__testUtils__/dedent.js';

import { Kind } from '../../language/kinds.js';
import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';
import { Source } from '../../language/source.js';

import { GraphQLError } from '../GraphQLError.js';
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/abort-signal-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expectJSON } from '../../__testUtils__/expectJSON.js';
import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js';

import type { DocumentNode } from '../../language/ast.js';
import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import { buildSchema } from '../../utilities/buildASTSchema.js';

Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/abstract-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON.js';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import {
assertInterfaceType,
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/defer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js';
import { promiseWithResolvers } from '../../jsutils/promiseWithResolvers.js';

import type { DocumentNode } from '../../language/ast.js';
import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import {
GraphQLList,
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/directives-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import { GraphQLObjectType } from '../../type/definition.js';
import { GraphQLString } from '../../type/scalars.js';
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js';
import { inspect } from '../../jsutils/inspect.js';

import { Kind } from '../../language/kinds.js';
import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import {
GraphQLInterfaceType,
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/lists-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expectJSON } from '../../__testUtils__/expectJSON.js';

import type { PromiseOrValue } from '../../jsutils/PromiseOrValue.js';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import type { GraphQLFieldResolver } from '../../type/definition.js';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/mutations-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, it } from 'mocha';
import { expectJSON } from '../../__testUtils__/expectJSON.js';
import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import { GraphQLObjectType } from '../../type/definition.js';
import { GraphQLInt } from '../../type/scalars.js';
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/nonnull-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js';

import type { PromiseOrValue } from '../../jsutils/PromiseOrValue.js';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import { GraphQLNonNull, GraphQLObjectType } from '../../type/definition.js';
import { GraphQLString } from '../../type/scalars.js';
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/oneof-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON.js';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import { buildSchema } from '../../utilities/buildASTSchema.js';

Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/resolve-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import type { GraphQLFieldConfig } from '../../type/definition.js';
import { GraphQLObjectType } from '../../type/definition.js';
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/schema-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import {
GraphQLList,
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { PromiseOrValue } from '../../jsutils/PromiseOrValue.js';
import { promiseWithResolvers } from '../../jsutils/promiseWithResolvers.js';

import type { DocumentNode } from '../../language/ast.js';
import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import {
GraphQLList,
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/subscribe-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isAsyncIterable } from '../../jsutils/isAsyncIterable.js';
import { isPromise } from '../../jsutils/isPromise.js';
import type { PromiseOrValue } from '../../jsutils/PromiseOrValue.js';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import { GraphQLList, GraphQLObjectType } from '../../type/definition.js';
import {
Expand Down
4 changes: 2 additions & 2 deletions src/execution/__tests__/sync-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON.js';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import { GraphQLObjectType } from '../../type/definition.js';
import { GraphQLString } from '../../type/scalars.js';
import { GraphQLSchema } from '../../type/schema.js';

import { validate } from '../../validation/validate.js';
import { validateSync as validate } from '../../validation/validate.js';

import { graphqlSync } from '../../graphql.js';

Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/union-interface-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON.js';

import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import {
GraphQLInterfaceType,
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GraphQLError } from '../../error/GraphQLError.js';

import { DirectiveLocation } from '../../language/directiveLocation.js';
import { Kind } from '../../language/kinds.js';
import { parse } from '../../language/parser.js';
import { parseSync as parse } from '../../language/parser.js';

import type {
GraphQLArgumentConfig,
Expand Down
4 changes: 2 additions & 2 deletions src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isPromise } from './jsutils/isPromise.js';
import type { Maybe } from './jsutils/Maybe.js';
import type { PromiseOrValue } from './jsutils/PromiseOrValue.js';

import { parse } from './language/parser.js';
import { parseSync as parse } from './language/parser.js';
import type { Source } from './language/source.js';

import type {
Expand All @@ -12,7 +12,7 @@ import type {
import type { GraphQLSchema } from './type/schema.js';
import { validateSchema } from './type/validate.js';

import { validate } from './validation/validate.js';
import { validateSync as validate } from './validation/validate.js';

import { execute } from './execution/execute.js';
import type { ExecutionResult } from './execution/types.js';
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export {
TokenKind,
// Parse
parse,
parseSync,
parseValue,
parseConstValue,
parseType,
Expand Down Expand Up @@ -247,6 +248,7 @@ export {

export type {
ParseOptions,
ParseCache,
SourceLocation,
// Visitor utilities
ASTVisitor,
Expand Down Expand Up @@ -356,6 +358,7 @@ export type {
// Validate GraphQL documents.
export {
validate,
validateSync,
ValidationContext,
// All validation rules in the GraphQL Specification.
specifiedRules,
Expand Down Expand Up @@ -402,7 +405,11 @@ export {
NoSchemaIntrospectionCustomRule,
} from './validation/index.js';

export type { ValidationRule } from './validation/index.js';
export type {
ValidationRule,
ValidateOptions,
ValidateCache,
} from './validation/index.js';

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

0 comments on commit 8fee71f

Please sign in to comment.