Skip to content

Commit e895df7

Browse files
committed
Allows to bypass SDL validation
1 parent e5109b3 commit e895df7

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,24 @@ describe('Schema Builder', () => {
787787
const errors = validateSchema(schema);
788788
expect(errors.length).to.equal(0);
789789
});
790+
791+
it('Rejects invalid SDL', () => {
792+
const doc = parse(`
793+
type Query {
794+
foo: String @unknown
795+
}
796+
`);
797+
expect(() => buildASTSchema(doc)).to.throw('Unknown directive "unknown".');
798+
});
799+
800+
it('Allows to disable SDL validation', () => {
801+
const body = `
802+
type Query {
803+
foo: String @unknown
804+
}
805+
`;
806+
buildSchema(body, { assumeValidSDL: true });
807+
});
790808
});
791809

792810
describe('Failures', () => {

src/utilities/__tests__/extendSchema-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,22 @@ describe('extendSchema', () => {
10181018
expect(isScalarType(arg1.type)).to.equal(true);
10191019
});
10201020

1021+
it('Rejects invalid SDL', () => {
1022+
const sdl = `
1023+
extend schema @unknown
1024+
`;
1025+
expect(() => extendTestSchema(sdl)).to.throw(
1026+
'Unknown directive "unknown".',
1027+
);
1028+
});
1029+
1030+
it('Allows to disable SDL validation', () => {
1031+
const sdl = `
1032+
extend schema @unknown
1033+
`;
1034+
extendTestSchema(sdl, { assumeValidSDL: true });
1035+
});
1036+
10211037
it('does not allow replacing a default directive', () => {
10221038
const sdl = `
10231039
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD

src/utilities/buildASTSchema.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ export type BuildSchemaOptions = {
8787
* Default: false
8888
*/
8989
commentDescriptions?: boolean,
90+
91+
/**
92+
* Set to true to assume the SDL is valid.
93+
*
94+
* Default: false
95+
*/
96+
assumeValidSDL?: boolean,
9097
};
9198

9299
/**
@@ -113,7 +120,9 @@ export function buildASTSchema(
113120
throw new Error('Must provide a document ast.');
114121
}
115122

116-
assertValidSDL(ast);
123+
if (!options || !options.assumeValidSDL) {
124+
assertValidSDL(ast);
125+
}
117126

118127
let schemaDef: ?SchemaDefinitionNode;
119128

src/utilities/extendSchema.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ type Options = {|
6767
* Default: false
6868
*/
6969
commentDescriptions?: boolean,
70+
71+
/**
72+
* Set to true to assume the SDL is valid.
73+
*
74+
* Default: false
75+
*/
76+
assumeValidSDL?: boolean,
7077
|};
7178

7279
/**
@@ -99,7 +106,9 @@ export function extendSchema(
99106
'Must provide valid Document AST',
100107
);
101108

102-
assertValidSDLExtension(schema, documentAST);
109+
if (!options || !options.assumeValidSDL) {
110+
assertValidSDLExtension(schema, documentAST);
111+
}
103112

104113
// Collect the type definitions and extensions found in the document.
105114
const typeDefinitionMap = Object.create(null);

0 commit comments

Comments
 (0)