本文整理汇总了C#中ValidationContext.Print方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationContext.Print方法的具体用法?C# ValidationContext.Print怎么用?C# ValidationContext.Print使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationContext
的用法示例。
在下文中一共展示了ValidationContext.Print方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<InlineFragment>(node =>
{
var type = context.TypeInfo.GetLastType();
if (node.Type != null && type != null && !type.IsCompositeType())
{
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.4.1.3",
InlineFragmentOnNonCompositeErrorMessage(context.Print(node.Type)),
node.Type));
}
});
_.Match<FragmentDefinition>(node =>
{
var type = context.TypeInfo.GetLastType();
if (type != null && !type.IsCompositeType())
{
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.4.1.3",
FragmentOnNonCompositeErrorMessage(node.Name, context.Print(node.Type)),
node.Type));
}
});
});
}
示例2: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<Field>(leave: node =>
{
var fieldDef = context.TypeInfo.GetFieldDef();
if (fieldDef == null)
{
return;
}
fieldDef.Arguments?.Apply(arg =>
{
var argAst = node.Arguments?.ValueFor(arg.Name);
var type = context.Schema.FindType(arg.Type);
if (argAst == null && type is NonNullGraphType)
{
context.ReportError(
new ValidationError(
context.OriginalQuery,
"5.3.3.2",
MissingFieldArgMessage(node.Name, arg.Name, context.Print(type)),
node));
}
});
});
_.Match<Directive>(leave: node =>
{
var directive = context.TypeInfo.GetDirective();
if (directive == null)
{
return;
}
directive.Arguments?.Apply(arg =>
{
var argAst = node.Arguments?.ValueFor(arg.Name);
var type = context.Schema.FindType(arg.Type);
if (argAst == null && type is NonNullGraphType)
{
context.ReportError(
new ValidationError(
context.OriginalQuery,
"5.3.3.2",
MissingDirectiveArgMessage(node.Name, arg.Name, context.Print(type)),
node));
}
});
});
});
}
示例3: Validate
public INodeVisitor Validate(ValidationContext context)
{
var varDefMap = new Dictionary<string, VariableDefinition>();
return new EnterLeaveListener(_ =>
{
_.Match<VariableDefinition>(
varDefAst => varDefMap[varDefAst.Name] = varDefAst
);
_.Match<Operation>(
enter: op => varDefMap = new Dictionary<string, VariableDefinition>(),
leave: op =>
{
var usages = context.GetRecursiveVariables(op);
usages.Apply(usage =>
{
var varName = usage.Node.Name;
VariableDefinition varDef;
if (!varDefMap.TryGetValue(varName, out varDef))
{
return;
}
if (varDef != null && usage.Type != null)
{
var varType = varDef.Type.GraphTypeFromType(context.Schema);
if (varType != null &&
!effectiveType(varType, varDef).IsSubtypeOf(usage.Type, context.Schema))
{
var error = new ValidationError(
context.OriginalQuery,
"5.7.6",
BadVarPosMessage(varName, context.Print(varType), context.Print(usage.Type)));
var source = new Source(context.OriginalQuery);
var varDefPos = new Location(source, varDef.SourceLocation.Start);
var usagePos = new Location(source, usage.Node.SourceLocation.Start);
error.AddLocation(varDefPos.Line, varDefPos.Column);
error.AddLocation(usagePos.Line, usagePos.Column);
context.ReportError(error);
}
}
});
}
);
});
}
示例4: getDirectiveLocationForAstPath
private DirectiveLocation getDirectiveLocationForAstPath(INode[] ancestors, ValidationContext context)
{
var appliedTo = ancestors[ancestors.Length - 1];
if (appliedTo is Directives || appliedTo is Arguments)
{
appliedTo = ancestors[ancestors.Length - 2];
}
if (appliedTo is Operation)
{
var op = (Operation) appliedTo;
switch (op.OperationType)
{
case OperationType.Query: return DirectiveLocation.Query;
case OperationType.Mutation: return DirectiveLocation.Mutation;
case OperationType.Subscription: return DirectiveLocation.Subscription;
}
}
if (appliedTo is Field) return DirectiveLocation.Field;
if (appliedTo is FragmentSpread) return DirectiveLocation.FragmentSpread;
if (appliedTo is InlineFragment) return DirectiveLocation.InlineFragment;
if (appliedTo is FragmentDefinition) return DirectiveLocation.FragmentDefinition;
throw new ExecutionError($"Unable to determine directive location for \"{context.Print(appliedTo)}\".");
}
示例5: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<VariableDefinition>(varDefAst =>
{
var name = varDefAst.Name;
var defaultValue = varDefAst.DefaultValue;
var inputType = context.TypeInfo.GetInputType();
if (inputType is NonNullGraphType && defaultValue != null)
{
var nonNullType = (NonNullGraphType) inputType;
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.7.2",
BadValueForNonNullArgMessage(
name,
context.Print(inputType),
context.Print(nonNullType.ResolvedType)),
defaultValue));
}
if (inputType != null && defaultValue != null)
{
var errors = inputType.IsValidLiteralValue(defaultValue, context.Schema).ToList();
if (errors.Any())
{
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.7.2",
BadValueForDefaultArgMessage(
name,
context.Print(inputType),
context.Print(defaultValue),
errors),
defaultValue));
}
}
});
});
}
示例6: Field
private void Field(GraphType type, Field field, ValidationContext context)
{
if (type == null)
{
return;
}
if (type.IsLeafType(context.Schema))
{
if (field.SelectionSet != null && field.SelectionSet.Selections.Any())
{
var error = new ValidationError(context.OriginalQuery, "5.2.3", NoSubselectionAllowedMessage(field.Name, context.Print(type)), field.SelectionSet);
context.ReportError(error);
}
}
else if(field.SelectionSet == null || !field.SelectionSet.Selections.Any())
{
var error = new ValidationError(context.OriginalQuery, "5.2.3", RequiredSubselectionMessage(field.Name, context.Print(type)), field);
context.ReportError(error);
}
}
示例7: Validate
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));
}
}
} 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));
}
}
}
});
});
}
示例8: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<VariableDefinition>(varDef =>
{
var type = varDef.Type.GraphTypeFromType(context.Schema);
if (!type.IsInputType())
{
context.ReportError(new ValidationError(context.OriginalQuery, "5.7.3", UndefinedVarMessage(varDef.Name, type != null ? context.Print(type) : varDef.Type.Name()), varDef));
}
});
});
}
示例9: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<InlineFragment>(node =>
{
var fragType = context.TypeInfo.GetLastType();
var parentType = context.TypeInfo.GetParentType().GetNamedType(context.Schema);
if (fragType != null && parentType != null && !context.Schema.DoTypesOverlap(fragType, parentType))
{
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.4.2.3",
TypeIncompatibleAnonSpreadMessage(context.Print(parentType), context.Print(fragType)),
node));
}
});
_.Match<FragmentSpread>(node =>
{
var fragName = node.Name;
var fragType = getFragmentType(context, fragName);
var parentType = context.TypeInfo.GetParentType().GetNamedType(context.Schema);
if (fragType != null && parentType != null && !context.Schema.DoTypesOverlap(fragType, parentType))
{
context.ReportError(new ValidationError(
context.OriginalQuery,
"5.4.2.3",
TypeIncompatibleSpreadMessage(fragName, context.Print(parentType), context.Print(fragType)),
node));
}
});
});
}
示例10: Validate
public INodeVisitor Validate(ValidationContext context)
{
return new EnterLeaveListener(_ =>
{
_.Match<Argument>(argAst =>
{
var argDef = context.TypeInfo.GetArgument();
if (argDef == null) return;
var type = context.Schema.FindType(argDef.Type);
var errors = type.IsValidLiteralValue(argAst.Value, context.Schema).ToList();
if (errors.Any())
{
var error = new ValidationError(
context.OriginalQuery,
"5.3.3.1",
BadValueMessage(argAst.Name, type, context.Print(argAst.Value), errors),
argAst);
context.ReportError(error);
}
});
});
}