Skip to content

Commit d77d661

Browse files
authored
add permanent flag for schema configuration property assumeValid (#4244)
closes #3448
1 parent 44e5d9a commit d77d661

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/type/__tests__/schema-test.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from '../introspection.js';
2525
import { GraphQLBoolean, GraphQLInt, GraphQLString } from '../scalars.js';
2626
import { GraphQLSchema } from '../schema.js';
27+
import { validateSchema } from '../validate.js';
2728

2829
describe('Type System: Schema', () => {
2930
it('Define sample schema', () => {
@@ -432,11 +433,21 @@ describe('Type System: Schema', () => {
432433
describe('Validity', () => {
433434
describe('when not assumed valid', () => {
434435
it('configures the schema to still needing validation', () => {
435-
expect(
436-
new GraphQLSchema({
437-
assumeValid: false,
438-
}).__validationErrors,
439-
).to.equal(undefined);
436+
const schema = new GraphQLSchema({
437+
assumeValid: false,
438+
});
439+
expect(schema.assumeValid).to.equal(false);
440+
expect(schema.__validationErrors).to.equal(undefined);
441+
});
442+
443+
it('configures the schema to have required validation even once validated', () => {
444+
const schema = new GraphQLSchema({
445+
assumeValid: false,
446+
});
447+
const validationErrors = validateSchema(schema);
448+
expect(validationErrors.length).to.be.greaterThan(0);
449+
expect(validationErrors).to.equal(schema.__validationErrors);
450+
expect(schema.assumeValid).to.equal(false);
440451
});
441452
});
442453

@@ -486,11 +497,11 @@ describe('Type System: Schema', () => {
486497

487498
describe('when assumed valid', () => {
488499
it('configures the schema to have no errors', () => {
489-
expect(
490-
new GraphQLSchema({
491-
assumeValid: true,
492-
}).__validationErrors,
493-
).to.deep.equal([]);
500+
const schema = new GraphQLSchema({
501+
assumeValid: true,
502+
});
503+
expect(schema.assumeValid).to.equal(true);
504+
expect(schema.__validationErrors).to.deep.equal([]);
494505
});
495506
});
496507
});

src/type/schema.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class GraphQLSchema {
138138
astNode: Maybe<SchemaDefinitionNode>;
139139
extensionASTNodes: ReadonlyArray<SchemaExtensionNode>;
140140

141-
// Used as a cache for validateSchema().
141+
assumeValid: boolean;
142142
__validationErrors: Maybe<ReadonlyArray<GraphQLError>>;
143143

144144
private _queryType: Maybe<GraphQLObjectType>;
@@ -159,6 +159,8 @@ export class GraphQLSchema {
159159
constructor(config: Readonly<GraphQLSchemaConfig>) {
160160
// If this schema was built from a source known to be valid, then it may be
161161
// marked with assumeValid to avoid an additional type system validation.
162+
this.assumeValid = config.assumeValid ?? false;
163+
// Used as a cache for validateSchema().
162164
this.__validationErrors = config.assumeValid === true ? [] : undefined;
163165

164166
this.description = config.description;
@@ -384,7 +386,7 @@ export class GraphQLSchema {
384386
extensions: this.extensions,
385387
astNode: this.astNode,
386388
extensionASTNodes: this.extensionASTNodes,
387-
assumeValid: this.__validationErrors !== undefined,
389+
assumeValid: this.assumeValid,
388390
};
389391
}
390392
}

0 commit comments

Comments
 (0)