UNPKG

831 BJavaScriptView Raw
1import { GraphQLError } from "../../error/GraphQLError.mjs";
2
3/**
4 * Unique argument names
5 *
6 * A GraphQL field or directive is only valid if all supplied arguments are
7 * uniquely named.
8 */
9export function UniqueArgumentNamesRule(context) {
10 var knownArgNames = Object.create(null);
11 return {
12 Field: function Field() {
13 knownArgNames = Object.create(null);
14 },
15 Directive: function Directive() {
16 knownArgNames = Object.create(null);
17 },
18 Argument: function Argument(node) {
19 var argName = node.name.value;
20
21 if (knownArgNames[argName]) {
22 context.reportError(new GraphQLError("There can be only one argument named \"".concat(argName, "\"."), [knownArgNames[argName], node.name]));
23 } else {
24 knownArgNames[argName] = node.name;
25 }
26
27 return false;
28 }
29 };
30}