knownArgumentNamesRule function

Visitor knownArgumentNamesRule(
  1. ValidationCtx context
)

Known argument names

A GraphQL field is only valid if all supplied arguments are defined by that field.

See https://spec.graphql.org/draft/#sec-Argument-Names See https://spec.graphql.org/draft/#sec-Directives-Are-In-Valid-Locations

Implementation

Visitor knownArgumentNamesRule(ValidationCtx context) {
  final typeInfo = context.typeInfo;
  final visitor = TypedVisitor();

  visitor.mergeInPlace(knownArgumentNamesOnDirectivesRule(context));
  visitor.add<ArgumentNode>((argNode) {
    final argDef = typeInfo.getArgument();
    final fieldDef = typeInfo.getFieldDef();
    final parentType = typeInfo.getParentType();

    if (argDef == null && fieldDef != null && parentType != null) {
      final argName = argNode.name.value;
      // TODO: final knownArgsNames = fieldDef.inputs.map((arg) => arg.name);
      // final suggestions = suggestionList(argName, knownArgsNames);
      context.reportError(
        GraphQLError(
          'Unknown argument "${argName}" on field "${parentType.name}.${fieldDef.name}".'
          // +    didYouMean(suggestions)
          ,
          locations: GraphQLErrorLocation.firstFromNodes(
            [argNode, argNode.name],
          ),
          extensions: _knownArgumentNamesSpec.extensions(),
        ),
      );
    }
  });
  return visitor;
}