swc/bundler/tests/.cache/deno/e50c78d40dc985f77ba8402b211ce55d4beb7863.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

30 lines
947 B
TypeScript

// Loaded from https://deno.land/x/graphql_deno@v15.0.0/lib/validation/rules/LoneSchemaDefinitionRule.js
import { GraphQLError } from '../../error/GraphQLError.js';
/**
* Lone Schema definition
*
* A GraphQL document is only valid if it contains only one schema definition.
*/
export function LoneSchemaDefinitionRule(context) {
const oldSchema = context.getSchema();
const alreadyDefined = oldSchema?.astNode ?? oldSchema?.getQueryType() ?? oldSchema?.getMutationType() ?? oldSchema?.getSubscriptionType();
let schemaDefinitionsCount = 0;
return {
SchemaDefinition(node) {
if (alreadyDefined) {
context.reportError(new GraphQLError('Cannot define a new schema within a schema extension.', node));
return;
}
if (schemaDefinitionsCount > 0) {
context.reportError(new GraphQLError('Must provide only one schema definition.', node));
}
++schemaDefinitionsCount;
}
};
}