Exemple #1
0
        public (QueryContentAppender appender, QueryRenderingContext context) AppendStartOfSelectionSet()
        {
            _content.AppendLine("{");
            _context = _context.IncreaseIndentationLevel();

            return(this, _context);
        }
Exemple #2
0
        /// <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());
        }
Exemple #3
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());
        }
Exemple #4
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());
        }
Exemple #5
0
        public QueryContentAppender AppendEndOfSelectionSet()
        {
            _context = _context.DecreaseIndentationLevel();

            return(Append($"{_context.RenderIndentationString()}}}"));
        }
Exemple #6
0
 public QueryContentAppender(QueryRenderingContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }