Beispiel #1
0
        public static string GetJSON(this IVariableContainer container)
        {
            var writer = new StringGraphQLWriter();

            writer.WriteLine("{");
            bool first = true;

            foreach (var v in container.Variables)
            {
                if (v.Value.HasValue)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        writer.Write(", ");
                    }
                    writer.Write("\"" + v.Key + "\": ");
                    v.Value.Write(writer);
                }
            }
            writer.WriteLine();
            writer.WriteLine("}");

            return(writer.CreateString());
        }
Beispiel #2
0
        public Command(INode o, string prefix, IHelper helper, string queryName)
        {
            Node   = o;
            Helper = helper;
            var writer = new StringGraphQLWriter();

            if (queryName != null)
            {
                var list = new Dictionary <string, IVariableReference>();
                o.GetVariables(list);
                writer.Write($"{prefix} {queryName}");
                if (list.Count > 0)
                {
                    writer.Write("(");
                    bool first = true;
                    foreach (var v in list)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            writer.Write(", ");
                        }
                        writer.Write($"${v.Key}: {v.Value.Type}");
                    }
                    writer.Write(")");
                }
            }
            o.Write(writer);
            QueryText = writer.CreateString();
            QueryName = queryName;
        }