Inheritance: AbstractNode, IDefinition, IHaveSelectionSet
        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;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Compares this instance to another instance by name.
 /// </summary>
 protected bool Equals(FragmentDefinition other)
 {
     return(string.Equals(Name, other.Name, StringComparison.InvariantCulture));
 }
 protected bool Equals(FragmentDefinition other)
 {
     return(string.Equals(Name, other.Name));
 }
 protected bool Equals(FragmentDefinition other)
 {
     return string.Equals(Name, other.Name);
 }