/// <inheritdoc /> public string Render(IGraphQLOperation query) { var context = new QueryRenderingContext(); var content = new QueryContentAppender(context); content.Append($"{Render(query.Type)} ") .Append(RenderOperationName(query.Name)) .Append(Render(query.SelectionSet, context)); return(content.ToString()); }
private string Render(ISelectionSet selectionSet, QueryRenderingContext context) { var content = new QueryContentAppender(context); (_, context) = content.AppendStartOfSelectionSet(); foreach (var selectionItem in selectionSet.Selections) { var selectionItemContent = selectionItem switch { IFieldSelectionItem fieldSelection => Render(fieldSelection, context), _ => throw new NotImplementedException($"Unable to render selection {selectionItem.GetType().FullName}") }; content.AppendLineWithIndentation($"{selectionItemContent}"); } content.AppendEndOfSelectionSet(); return(content.ToString()); }
private string Render(IFieldSelectionItem fieldSelection, QueryRenderingContext context) { var content = new QueryContentAppender(context); if (!string.IsNullOrWhiteSpace(fieldSelection.Alias)) { content.Append($"{fieldSelection.Alias}: "); } content.Append(fieldSelection.FieldName); if (fieldSelection.Arguments.Count != 0) { content.Append(Render(fieldSelection.Arguments.ToList())); } if (fieldSelection.SelectionSet != null) { content.Append($" {Render(fieldSelection.SelectionSet, context)}"); } return(content.ToString()); }