Esempio n. 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", 1 },
                },
            });

            Assert.Equal(2, resolved);

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

            Assert.Equal(10, resolvedTwo);
        }
Esempio n. 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());
        }
Esempio n. 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"));
        }
Esempio n. 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"));
        }
Esempio n. 5
0
        public async Task GraphQLFieldQuery_Test()
        {
            var root         = new RootQuery();
            var mutation     = new RootMutation();
            var schema       = new GraphQLRootSchema(root, mutation);
            var queryBuilder = new BasicQueryBuilder();
            var executor     = new DocumentExecuter();


            schema.Register(queryBuilder);
            Assert.True(schema.Query.HasField("defaultTest"));

            var result = await executor.ExecuteAsync(new ExecutionOptions()
            {
                Schema        = schema,
                Query         = "query TestQuery { defaultTest(returnOne: 5, returnTwo: 5) }",
                OperationName = "TestQuery"
            }).ConfigureAwait(false);


            Assert.NotNull(result);
            Assert.NotNull(result?.Data);
            Assert.Equal(10, ((Dictionary <string, object>)result?.Data)["defaultTest"]);
        }
Esempio n. 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);
        }