コード例 #1
0
        public static void WriteStringValue(
            this DocumentWriter writer,
            StringValueNode node)
        {
            if (node.Block)
            {
                writer.Write("\"\"\"");

                var lines = node.Value
                            .Replace("\"\"\"", "\\\"\"\"")
                            .Replace("\r", string.Empty)
                            .Split('\n');

                foreach (var line in lines)
                {
                    writer.WriteLine();
                    writer.WriteIndentation();
                    writer.Write(line);
                }

                writer.WriteLine();
                writer.WriteIndentation();
                writer.Write("\"\"\"");
            }
            else
            {
                writer.Write($"\"{WriteEscapeCharacters(node.Value)}\"");
            }
        }
コード例 #2
0
 public static void WriteVariable(
     this DocumentWriter writer,
     VariableNode node)
 {
     writer.Write('$');
     writer.Write(node.Name.Value);
 }
コード例 #3
0
 public static void WriteListType(
     this DocumentWriter writer,
     ListTypeNode node)
 {
     writer.Write('[');
     writer.WriteType(node.Type);
     writer.Write(']');
 }
コード例 #4
0
 public static void WriteObjectValue(
     this DocumentWriter writer,
     ObjectValueNode node)
 {
     writer.Write("{ ");
     writer.WriteMany(node.Fields, (n, w) => w.WriteObjectField(n));
     writer.Write(" }");
 }
コード例 #5
0
 public static void WriteListValue(
     this DocumentWriter writer,
     ListValueNode node)
 {
     writer.Write("[ ");
     writer.WriteMany(node.Items, (n, w) => w.WriteValue(n));
     writer.Write(" ]");
 }
コード例 #6
0
 public static void WriteField(
     this DocumentWriter writer,
     NameNode name,
     IValueNode value)
 {
     writer.Write(name.Value);
     writer.Write(": ");
     writer.WriteValue(value);
 }
コード例 #7
0
 public static void WriteNonNullType(
     this DocumentWriter writer,
     NonNullTypeNode node)
 {
     writer.WriteType(node.Type);
     writer.Write('!');
 }
コード例 #8
0
        public static void WriteDirective(
            this DocumentWriter writer,
            DirectiveNode node)
        {
            writer.Write('@');

            writer.WriteName(node.Name);

            if (node.Arguments.Any())
            {
                writer.Write('(');

                writer.WriteMany(node.Arguments, (n, w) => w.WriteArgument(n));

                writer.Write(')');
            }
        }
コード例 #9
0
        public static void WriteMany <T>(
            this DocumentWriter writer,
            IEnumerable <T> items,
            Action <T, DocumentWriter> action,
            string separator)
        {
            if (items.Any())
            {
                action(items.First(), writer);

                foreach (T item in items.Skip(1))
                {
                    writer.Write(separator);
                    action(item, writer);
                }
            }
        }
コード例 #10
0
 public static void WriteFloatValue(
     this DocumentWriter writer,
     FloatValueNode node)
 {
     writer.Write(node.Value);
 }
コード例 #11
0
        protected override void VisitOperationDefinition(
            OperationDefinitionNode node)
        {
            if (node.Name != null)
            {
                _writer.Write(node.Operation.ToString().ToLowerInvariant());
                _writer.WriteSpace();

                VisitName(node.Name);
                if (node.VariableDefinitions.Any())
                {
                    _writer.Write('(');

                    WriteMany(
                        node.VariableDefinitions,
                        VisitVariableDefinition);

                    _writer.Write(')');
                }

                WriteMany(node.Directives, VisitDirective, " ");

                _writer.WriteSpace();
            }

            VisitSelectionSet(node.SelectionSet);
        }
コード例 #12
0
 public static void WriteName(
     this DocumentWriter writer,
     NameNode node)
 {
     writer.Write(node.Value);
 }
コード例 #13
0
 public static void WriteNullValue(
     this DocumentWriter writer,
     NullValueNode node)
 {
     writer.Write("null");
 }
コード例 #14
0
 public static void WriteEnumValue(
     this DocumentWriter writer,
     EnumValueNode node)
 {
     writer.Write(node.Value);
 }
コード例 #15
0
 public static void WriteBooleanValue(
     this DocumentWriter writer,
     BooleanValueNode node)
 {
     writer.Write(node.Value.ToString().ToLowerInvariant());
 }