1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { groupBy } from '../../jsutils/groupBy.mjs';
- import { GraphQLError } from '../../error/GraphQLError.mjs';
- export function UniqueArgumentNamesRule(context) {
- return {
- Field: checkArgUniqueness,
- Directive: checkArgUniqueness,
- };
- function checkArgUniqueness(parentNode) {
- var _parentNode$arguments;
-
-
- const argumentNodes =
- (_parentNode$arguments = parentNode.arguments) !== null &&
- _parentNode$arguments !== void 0
- ? _parentNode$arguments
- : [];
- const seenArgs = groupBy(argumentNodes, (arg) => arg.name.value);
- for (const [argName, argNodes] of seenArgs) {
- if (argNodes.length > 1) {
- context.reportError(
- new GraphQLError(
- `There can be only one argument named "${argName}".`,
- {
- nodes: argNodes.map((node) => node.name),
- },
- ),
- );
- }
- }
- }
- }
|