public INodeVisitor Validate(ValidationContext context)
 {
     return(new EnterLeaveListener(_ =>
     {
         _.Match <Argument>(node =>
         {
             var ancestors = context.TypeInfo.GetAncestors();
             var argumentOf = ancestors[ancestors.Length - 2];
             if (argumentOf is Field)
             {
                 var fieldDef = context.TypeInfo.GetFieldDef();
                 if (fieldDef != null)
                 {
                     var fieldArgDef = fieldDef.Arguments?.Find(node.Name);
                     if (fieldArgDef == null)
                     {
                         var parentType = context.TypeInfo.GetParentType();
                         Invariant.Check(parentType != null, "Parent type must not be null.");
                         context.ReportError(new ValidationError(
                                                 context.OriginalQuery,
                                                 "5.3.1",
                                                 UnknownArgMessage(
                                                     node.Name,
                                                     fieldDef.Name,
                                                     context.Print(parentType),
                                                     StringUtils.SuggestionList(node.Name, fieldDef.Arguments?.Select(q => q.Name))),
                                                 node)
                         {
                             Path = context.TypeInfo.GetPath()
                         });
                     }
                 }
             }
             else if (argumentOf is Directive)
             {
                 var directive = context.TypeInfo.GetDirective();
                 if (directive != null)
                 {
                     var directiveArgDef = directive.Arguments?.Find(node.Name);
                     if (directiveArgDef == null)
                     {
                         context.ReportError(new ValidationError(
                                                 context.OriginalQuery,
                                                 "5.3.1",
                                                 UnknownDirectiveArgMessage(
                                                     node.Name,
                                                     directive.Name,
                                                     StringUtils.SuggestionList(node.Name, directive.Arguments?.Select(q => q.Name))),
                                                 node)
                         {
                             Path = context.TypeInfo.GetPath()
                         });
                     }
                 }
             }
         });
     }));
 }
 public void ReportError(ValidationError error)
 {
     Invariant.Check(error != null, "Must provide a validation error.");
     _errors.Add(error);
 }