UNPKG

1.03 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.UniqueOperationNamesRule = UniqueOperationNamesRule;
7
8var _GraphQLError = require("../../error/GraphQLError.js");
9
10/**
11 * Unique operation names
12 *
13 * A GraphQL document is only valid if all defined operations have unique names.
14 */
15function UniqueOperationNamesRule(context) {
16 var knownOperationNames = Object.create(null);
17 return {
18 OperationDefinition: function OperationDefinition(node) {
19 var operationName = node.name;
20
21 if (operationName) {
22 if (knownOperationNames[operationName.value]) {
23 context.reportError(new _GraphQLError.GraphQLError("There can be only one operation named \"".concat(operationName.value, "\"."), [knownOperationNames[operationName.value], operationName]));
24 } else {
25 knownOperationNames[operationName.value] = operationName;
26 }
27 }
28
29 return false;
30 },
31 FragmentDefinition: function FragmentDefinition() {
32 return false;
33 }
34 };
35}