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


C# ValidationContext.GetFragmentSpreads方法代码示例

本文整理汇总了C#中ValidationContext.GetFragmentSpreads方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationContext.GetFragmentSpreads方法的具体用法?C# ValidationContext.GetFragmentSpreads怎么用?C# ValidationContext.GetFragmentSpreads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ValidationContext的用法示例。


在下文中一共展示了ValidationContext.GetFragmentSpreads方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: detectCycleRecursive

        private void detectCycleRecursive(
            FragmentDefinition fragment,
            Stack<FragmentSpread> spreadPath,
            LightweightCache<string, bool> visitedFrags,
            LightweightCache<string, int> spreadPathIndexByName,
            ValidationContext context)
        {
            var fragmentName = fragment.Name;
            visitedFrags[fragmentName] = true;

            var spreadNodes = context.GetFragmentSpreads(fragment.SelectionSet).ToArray();
            if (!spreadNodes.Any())
            {
                return;
            }

            spreadPathIndexByName[fragmentName] = spreadPath.Count;

            foreach (var spreadNode in spreadNodes)
            {
                var spreadName = spreadNode.Name;
                var cycleIndex = spreadPathIndexByName[spreadName];

                if (cycleIndex == -1)
                {
                    spreadPath.Push(spreadNode);

                    if (!visitedFrags[spreadName])
                    {
                        var spreadFragment = context.GetFragment(spreadName);
                        if (spreadFragment != null)
                        {
                            detectCycleRecursive(
                                spreadFragment,
                                spreadPath,
                                visitedFrags,
                                spreadPathIndexByName,
                                context);
                        }
                    }

                    spreadPath.Pop();
                }
                else
                {
                    var cyclePath = spreadPath.Reverse().Skip(cycleIndex).ToArray();
                    var nodes = cyclePath.OfType<INode>().Concat(new[] {spreadNode}).ToArray();

                    context.ReportError(new ValidationError(
                        context.OriginalQuery,
                        "5.4",
                        CycleErrorMessage(spreadName, cyclePath.Select(x => x.Name).ToArray()),
                        nodes));
                }
            }

            spreadPathIndexByName[fragmentName] = -1;
        }
开发者ID:graphql-dotnet,项目名称:graphql-dotnet,代码行数:58,代码来源:NoFragmentCycles.cs


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