Esempio n. 1
0
        private void CollectFields(ExecutionContext context, IGraphType specificType, SelectionSet selectionSet, ref List <string> visitedFragmentNames) //TODO: can be completely eliminated? see Fields.Add
        {
            if (selectionSet != null)
            {
                foreach (var selection in selectionSet.SelectionsList)
                {
                    if (selection is Field field)
                    {
                        if (!ExecutionHelper.ShouldIncludeNode(context, field.Directives))
                        {
                            continue;
                        }

                        Add(field);
                    }
                    else if (selection is FragmentSpread spread)
                    {
                        if ((visitedFragmentNames != null && visitedFragmentNames.Contains(spread.Name)) ||
                            !ExecutionHelper.ShouldIncludeNode(context, spread.Directives))
                        {
                            continue;
                        }

                        (visitedFragmentNames ??= new List <string>()).Add(spread.Name);

                        var fragment = context.Fragments.FindDefinition(spread.Name);
                        if (fragment == null ||
                            !ExecutionHelper.ShouldIncludeNode(context, fragment.Directives) ||
                            !ExecutionHelper.DoesFragmentConditionMatch(context, fragment.Type.Name, specificType))
                        {
                            continue;
                        }

                        CollectFields(context, specificType, fragment.SelectionSet, ref visitedFragmentNames);
                    }
                    else if (selection is InlineFragment inline)
                    {
                        var name = inline.Type != null ? inline.Type.Name : specificType.Name;

                        if (!ExecutionHelper.ShouldIncludeNode(context, inline.Directives) ||
                            !ExecutionHelper.DoesFragmentConditionMatch(context, name, specificType))
                        {
                            continue;
                        }

                        CollectFields(context, specificType, inline.SelectionSet, ref visitedFragmentNames);
                    }
                }
            }
        }