public IEnumerable<FragmentSpread> GetFragmentSpreads(SelectionSet node) { var spreads = new List<FragmentSpread>(); var setsToVisit = new Stack<SelectionSet>(new[] {node}); while (setsToVisit.Any()) { var set = setsToVisit.Pop(); set.Selections.Apply(selection => { if (selection is FragmentSpread) { spreads.Add((FragmentSpread)selection); } else { var hasSet = selection as IHaveSelectionSet; if (hasSet?.SelectionSet != null) { setsToVisit.Push(hasSet.SelectionSet); } } }); } return spreads; }
public SelectionSet Merge(SelectionSet otherSelection) { var newSelection = SelectionsList.Union(otherSelection.SelectionsList).ToList(); return(new SelectionSet(newSelection)); }
protected bool Equals(SelectionSet selectionSet) { return(false); }
public Dictionary<string, Fields> CollectFields( ExecutionContext context, IGraphType specificType, SelectionSet selectionSet, Dictionary<string, Fields> fields, List<string> visitedFragmentNames) { if (fields == null) { fields = new Dictionary<string, Fields>(); } selectionSet.Selections.Apply(selection => { if (selection is Field) { var field = (Field)selection; if (!ShouldIncludeNode(context, field.Directives)) { return; } var name = field.Alias ?? field.Name; if (!fields.ContainsKey(name)) { fields[name] = new Fields(); } fields[name].Add(field); } else if (selection is FragmentSpread) { var spread = (FragmentSpread)selection; if (visitedFragmentNames.Contains(spread.Name) || !ShouldIncludeNode(context, spread.Directives)) { return; } visitedFragmentNames.Add(spread.Name); var fragment = context.Fragments.FindDefinition(spread.Name); if (fragment == null || !ShouldIncludeNode(context, fragment.Directives) || !DoesFragmentConditionMatch(context, fragment.Type.Name, specificType)) { return; } CollectFields(context, specificType, fragment.SelectionSet, fields, visitedFragmentNames); } else if (selection is InlineFragment) { var inline = (InlineFragment)selection; var name = inline.Type != null ? inline.Type.Name : specificType.Name; if (!ShouldIncludeNode(context, inline.Directives) || !DoesFragmentConditionMatch(context, name, specificType)) { return; } CollectFields(context, specificType, inline.SelectionSet, fields, visitedFragmentNames); } }); return fields; }
protected bool Equals(SelectionSet selectionSet) { return false; }
protected bool Equals(SelectionSet selectionSet) => false;
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); } } } }
public InlineFragment(SelectionSet selectionSet) { #pragma warning disable CS0612 // Type or member is obsolete SelectionSet = selectionSet; #pragma warning restore CS0612 // Type or member is obsolete }