コード例 #1
0
        public void TestMutation()
        {
            string query    = @"{ ""query"": ""mutation ($human:HumanInput!){ createHuman(human: $human) { id fullname } }"", ""variables"": { ""human"": { ""fullname"": ""Bobba Fett"",""id"": ""3"" } } }";
            string expected = @"{ ""data"": { ""createHuman"": { ""id"": ""3"",""fullname"": ""Bobba Fett"" } } }";

            StarWarsSchema swss   = this._provider.GetRequiredService <StarWarsSchema>();
            var            result = swss.Execute(_ =>
            {
                //get the input into GraphQL format
                GraphQL.Inputs queryInputs = query.ToInputs();
                foreach (KeyValuePair <string, object> qIn in queryInputs)
                {
                    if (qIn.Key == "variables")
                    {
                        string json = JsonConvert.SerializeObject(qIn.Value, Formatting.Indented);
                        _.Inputs    = json.ToInputs();
                    }
                    if (qIn.Key == "query")
                    {
                        _.Query = qIn.Value.ToString();
                    }
                }
            });

            _output.WriteLine("Query:" + query);
            _output.WriteLine("Result:" + result);
            JToken actualJson   = JToken.Parse(result);
            JToken expectedJson = JToken.Parse(expected);

            Assert.Equal(expectedJson.ToString(), actualJson.ToString());
        }
コード例 #2
0
        public void ValidSchemaVariables(string query, string expected)
        {
            //
            StarWarsSchema swss   = this._provider.GetRequiredService <StarWarsSchema>();
            var            result = swss.Execute(x =>
            {
                x.Query = query;
            });

            _output.WriteLine("Query:" + query);
            _output.WriteLine("Result:" + result);
            JToken actualJson   = JToken.Parse(result);
            JToken expectedJson = JToken.Parse(expected);

            Assert.Equal(expectedJson.ToString(), actualJson.ToString());
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: benCoomes/StarWarsQL
        static void Main(string[] args)
        {
            var query = ResolveQuery(args);

            if (string.IsNullOrWhiteSpace(query))
            {
                Console.WriteLine("No query argument provided, or failed to parse query. Provide either a query or the named of a stored query. Stored queries: \n");
                foreach (var name in NamedQueries.Keys)
                {
                    Console.WriteLine(name);
                }
                return;
            }

            Console.WriteLine(StarWarsSchema.Execute(query));
        }