Beispiel #1
0
        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());
        }
Beispiel #2
0
        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());
        }