コード例 #1
0
        public void DefaultValue_Test()
        {
            var root         = new RootQuery();
            var mutation     = new RootMutation();
            var schema       = new GraphQlRootSchema(root, mutation);
            var queryBuilder = new BasicQueryBuilder();

            schema.Register(queryBuilder);
            var resolved = schema.Query.Fields.First(p => p.Name == "defaultTest").Resolver.Resolve(
                new ResolveFieldContext()
            {
                Arguments = new Dictionary <string, object>()
                {
                    { "returnOne", "Foo Bar and Eggs" },
                },
            });

            Assert.Equal("Foo Bar and EggsHello World", resolved);

            var resolvedTwo = schema.Query.Fields.First(p => p.Name == "defaultTest").Resolver.Resolve(
                new ResolveFieldContext()
            {
                Arguments = new Dictionary <string, object>()
                {
                    { "returnOne", "One" },
                    { "returnTwo", "Two" },
                },
            });

            Assert.Equal("OneTwo", resolvedTwo);
        }
コード例 #2
0
        public void ConnectionValue_Test()
        {
            var root         = new RootQuery();
            var mutation     = new RootMutation();
            var schema       = new GraphQlRootSchema(root, mutation);
            var queryBuilder = new BasicQueryBuilder();

            schema.Register(queryBuilder);
            var actual = (Connection <string>)schema.Query.Fields.First(p => p.Name == "connectionTest").Resolver
                         .Resolve(new ResolveFieldContext()
            {
                Arguments = new Dictionary <string, object>()
                {
                    { "returnOne", "One" },
                    { "returnTwo", "Two" },
                },
            });

            IEnumerable <string> Expected()
            {
                yield return("One");

                yield return("Two");
            }

            Assert.True(!Expected().Except(actual.Items).Any() && Expected().Count() == actual.Items.Count());
        }
コード例 #3
0
        public void RegisterMutationQuery_Test()
        {
            var root         = new RootQuery();
            var mutation     = new RootMutation();
            var schema       = new GraphQlRootSchema(root, mutation);
            var queryBuilder = new BasicQueryBuilder();

            queryBuilder.RegisterMutationQueries(mutation);
            Assert.True(schema.Mutation.HasField("mutationTest"));
        }
コード例 #4
0
        public void RegisterAll_Test()
        {
            var root         = new RootQuery();
            var mutation     = new RootMutation();
            var schema       = new GraphQlRootSchema(root, mutation);
            var queryBuilder = new BasicQueryBuilder();

            schema.Register(queryBuilder);
            Assert.True(schema.Query.HasField("defaultTest"));
            Assert.True(schema.Query.HasField("connectionTest"));
            Assert.True(schema.Mutation.HasField("mutationTest"));
        }
コード例 #5
0
        public void GraphQLFieldQuery_Test()
        {
            var root         = new RootQuery();
            var mutation     = new RootMutation();
            var schema       = new GraphQlRootSchema(root, mutation);
            var queryBuilder = new BasicQueryBuilder();
            var executor     = new GraphQlExecuterProvider(schema);

            schema.Register(queryBuilder);
            var result = executor.ExecuteRequestAsync(new GraphQlRequest()
            {
                Query = @"query {
                            defaultTest(returnOne: ""Hello"", returnTwo: ""World"")
                        }",
            }).Result;

            Assert.Equal("HelloWorld", ((dynamic)result.Data)["defaultTest"]);
        }
コード例 #6
0
        public void MutationValue_Test()
        {
            var root         = new RootQuery();
            var mutation     = new RootMutation();
            var schema       = new GraphQlRootSchema(root, mutation);
            var queryBuilder = new BasicQueryBuilder();

            schema.Register(queryBuilder);
            var actual = schema.Mutation.Fields.First(p => p.Name == "mutationTest").Resolver.Resolve(
                new ResolveFieldContext()
            {
                Arguments = new Dictionary <string, object>()
                {
                    {
                        "input", new TestInputType()
                        {
                            Input = "Hello World",
                        }
                    },
                },
            });

            Assert.Equal("Hello World", actual);
        }