当前位置: 首页>>代码示例>>C#>>正文


C# ValidationContext.Print方法代码示例

本文整理汇总了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));
                    }
                });
            });
        }
开发者ID:graphql-dotnet,项目名称:graphql-dotnet,代码行数:31,代码来源:FragmentsOnCompositeTypes.cs

示例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));
                        }
                    });
                });
            });
        }
开发者ID:mwatts,项目名称:graphql-dotnet,代码行数:57,代码来源:ProvidedNonNullArguments.cs

示例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);
                                }
                            }
                        });
                    }
                );
            });
        }
开发者ID:graphql-dotnet,项目名称:graphql-dotnet,代码行数:50,代码来源:VariablesInAllowedPosition.cs

示例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)}\".");
        }
开发者ID:graphql-dotnet,项目名称:graphql-dotnet,代码行数:26,代码来源:KnownDirectives.cs

示例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));
                        }
                    }
                });
            });
        }
开发者ID:graphql-dotnet,项目名称:graphql-dotnet,代码行数:42,代码来源:DefaultValuesOfCorrectType.cs

示例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);
            }
        }
开发者ID:mwatts,项目名称:graphql-dotnet,代码行数:21,代码来源:ScalarLeafs.cs

示例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));
                     }
                 }
             }
         });
     });
 }
开发者ID:graphql-dotnet,项目名称:graphql-dotnet,代码行数:51,代码来源:KnownArgumentNames.cs

示例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));
                    }
                });
            });
        }
开发者ID:graphql-dotnet,项目名称:graphql-dotnet,代码行数:15,代码来源:VariablesAreInputTypes.cs

示例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));
                    }
                });
            });
        }
开发者ID:mwatts,项目名称:graphql-dotnet,代码行数:36,代码来源:PossibleFragmentSpreads.cs

示例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);
                    }
                });
            });
        }
开发者ID:mwatts,项目名称:graphql-dotnet,代码行数:23,代码来源:ArgumentsOfCorrectType.cs


注:本文中的ValidationContext.Print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。