swc/bundler/tests/.cache/deno/c76ca21f9dfe95b39bd838a0ef3cb4d5492970ee.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
904 B
TypeScript

// Loaded from https://deno.land/x/graphql_deno@v15.0.0/lib/validation/rules/UniqueOperationNamesRule.js
import { GraphQLError } from '../../error/GraphQLError.js';
/**
* Unique operation names
*
* A GraphQL document is only valid if all defined operations have unique names.
*/
export function UniqueOperationNamesRule(context) {
const knownOperationNames = Object.create(null);
return {
OperationDefinition(node) {
const operationName = node.name;
if (operationName) {
if (knownOperationNames[operationName.value]) {
context.reportError(new GraphQLError(`There can be only one operation named "${operationName.value}".`, [knownOperationNames[operationName.value], operationName]));
} else {
knownOperationNames[operationName.value] = operationName;
}
}
return false;
},
FragmentDefinition: () => false
};
}