protected override SelectionSetNode RewriteSelectionSet( SelectionSetNode node, Context context) { SelectionSetNode current = node; var selections = new List <ISelectionNode>(current.Selections); ISet <FieldDependency> dependencies = _dependencyResolver.GetFieldDependencies( context.Document, current, context.TypeContext); RemoveDelegationFields(current, context, selections); AddDependencies(context.TypeContext, selections, dependencies); if (!selections.OfType <FieldNode>().Any(n => n.Name.Value == WellKnownFieldNames.TypeName)) { selections.Add(CreateField(WellKnownFieldNames.TypeName)); } current = current.WithSelections(selections); current = base.RewriteSelectionSet(current, context); current = OnRewriteSelectionSet(current, context); return(current); }
protected override SelectionSetNode RewriteSelectionSet( SelectionSetNode node, object?context) { SelectionSetNode current = base.RewriteSelectionSet(node, context); var test = node != _operation?.SelectionSet; if (node != _operation?.SelectionSet && !current.Selections.OfType <FieldNode>().Any(t => t.Alias is null && t.Name.Value.EqualsOrdinal(_typeName))) { List <ISelectionNode> selections = current.Selections.ToList(); selections.Insert(0, new FieldNode( null, new NameNode(_typeName), null, Array.Empty <DirectiveNode>(), Array.Empty <ArgumentNode>(), null)); current = current.WithSelections(selections); } return(current); }
protected override SelectionSetNode RewriteSelectionSet( SelectionSetNode node, Context context) { SelectionSetNode current = base.RewriteSelectionSet(node, context); if (NeedsEntityIdFields(context)) { List <ISelectionNode> selections = current.Selections.ToList(); foreach (var objectType in context.Schema.GetPossibleTypes(context.Types.Peek())) { SelectionSetNode entityDefinition = objectType.GetEntityDefinition(); List <ISelectionNode> fields = new(); foreach (var selection in entityDefinition.Selections) { fields.Add(selection); } selections.Add(new InlineFragmentNode( null, new NamedTypeNode(objectType.Name.Value), new List <DirectiveNode>(), new SelectionSetNode(fields))); } current = current.WithSelections(selections); } return(current); }
public SelectionInfo( INamedType type, SelectionSetNode selectionSet, IReadOnlyList <FieldSelection> fields, IReadOnlyList <IFragmentNode> fragments) { Type = type ?? throw new ArgumentNullException(nameof(type)); SelectionSet = selectionSet ?? throw new ArgumentNullException(nameof(selectionSet)); Fields = fields ?? throw new ArgumentNullException(nameof(fields)); Fragments = fragments ?? throw new ArgumentNullException(nameof(fragments)); ExpandedSelectionSet = selectionSet.WithSelections( fields.Select(t => t.Selection).ToList()); }
private (IOutputType, SelectionSetNode) MergeSelection( SelectionSetNode selectionSet, IFieldSelection selection) { if (selectionSet == null) { selectionSet = selection.Selection.SelectionSet; } else { selectionSet = selectionSet.WithSelections( selectionSet.Selections.Concat( selection.Selection.SelectionSet.Selections) .ToList()); } return(selection.Field.Type, selectionSet); }
protected override SelectionSetNode RewriteSelectionSet( SelectionSetNode node, string schemaName) { var selections = new List <ISelectionNode>(); foreach (ISelectionNode selection in node.Selections) { if ((IsRelevant(selection, schemaName))) { selections.Add(selection); } } return(base.RewriteSelectionSet( node.WithSelections(selections), schemaName)); }