mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
30 lines
904 B
TypeScript
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
|
|
};
|
|
} |