private void CollectFieldsAndFragmentNames( TypeDefinition parentType, SelectionSet selectionSet, Dictionary <string, List <FieldDefPair> > nodeAndDefs, Dictionary <string, bool> fragments) { var selections = selectionSet.ToList(); for (var i = 0; i < selections.Count; i++) { var selection = selections[i]; if (selection is FieldSelection field) { var fieldName = field.Name; FieldDefinition?fieldDef = null; if (parentType is not null && (IsObjectDefinition(parentType) || IsInterfaceType(parentType))) { fieldDef = _context.Schema.GetField(parentType.Name, fieldName); } var responseName = field.AliasOrName; if (!nodeAndDefs.ContainsKey(responseName)) { nodeAndDefs[responseName] = new List <FieldDefPair>(); } nodeAndDefs[responseName].Add(new FieldDefPair { ParentType = parentType, Field = field, FieldDef = fieldDef }); } else if (selection is FragmentSpread fragmentSpread) { fragments[fragmentSpread.FragmentName] = true; } else if (selection is InlineFragment inlineFragment) { var typeCondition = inlineFragment.TypeCondition; if (typeCondition is not null) { var inlineFragmentType = _context.Schema.GetNamedType(typeCondition.Name) ?? parentType; CollectFieldsAndFragmentNames( inlineFragmentType, inlineFragment.SelectionSet, nodeAndDefs, fragments); } } } }
/// <summary> /// Support for InsertAfter and InsertBefore. An offset of 0 will insert before the current /// element. 1 after. /// </summary> /// /// <param name="target"> /// The target object /// </param> /// <param name="offset"> /// The offset from the targe object to insert /// </param> /// /// <returns> /// The current CQ object /// </returns> private CQ InsertAtOffset(IDomObject target, int offset) { int index = target.Index; // must enumerate the list since it can be altered by the loop var list = SelectionSet.ToList(); foreach (var item in list) { target.ParentNode.ChildNodes.Insert(index + offset, item); index++; } return(this); }