public void SupportsComments()
        {
            var schemaProvider = SchemaBuilder.FromObject <TestSchema>();
            // Add a argument field with a require parameter
            var tree = new GraphQLCompiler(schemaProvider, new DefaultMethodProvider()).Compile(@"
            # hey there
            query {
                # yep
                person(id: ""cccccccc-bbbb-4444-1111-ccddeeff0033"") { # this is a good field
                    id
                    # more comments
                    projects { id name }
                    # down, why not
                }
                # yo
            } # look at me
# no thanks!").Operations.First();

            Assert.Single(tree.QueryFields);
            dynamic result = tree.Execute(new TestSchema(), null);

            // we only have the fields requested
            Assert.Equal(1, result.GetType().GetFields().Length);
            Assert.Equal(2, result.person.GetType().GetFields().Length);
            Assert.Equal("id", result.person.GetType().GetFields()[0].Name);
            Assert.Equal(new Guid("cccccccc-bbbb-4444-1111-ccddeeff0033"), result.person.id);
        }
        public void SupportsArgumentsAutoWithGuid()
        {
            var schemaProvider = SchemaBuilder.FromObject <TestSchema>();
            // Add a argument field with a require parameter
            var tree = new GraphQLCompiler(schemaProvider, new DefaultMethodProvider()).Compile(@"query {
                project(id: ""aaaaaaaa-bbbb-4444-1111-ccddeeff0022"") { id }
            }").Operations.First();

            Assert.Single(tree.QueryFields);
            dynamic result = tree.Execute(new TestSchema(), null);

            // we only have the fields requested
            Assert.Equal(1, result.project.GetType().GetFields().Length);
            Assert.Equal("id", result.project.GetType().GetFields()[0].Name);
            Assert.Equal(new Guid("aaaaaaaa-bbbb-4444-1111-ccddeeff0022"), result.project.id);
        }
        public void SupportsQueryKeyword()
        {
            var tree = new GraphQLCompiler(SchemaBuilder.FromObject <TestSchema>(), new DefaultMethodProvider()).Compile(@"query {
	people { id }
}").Operations.First();

            Assert.Single(tree.QueryFields);
            dynamic result = tree.Execute(new TestSchema(), null);

            Assert.Equal(1, Enumerable.Count(result.people));
            var person = Enumerable.ElementAt(result.people, 0);

            // we only have the fields requested
            Assert.Equal(1, person.GetType().GetFields().Length);
            Assert.Equal("id", person.GetType().GetFields()[0].Name);
        }
        public void SupportsArgumentsAuto()
        {
            var schemaProvider = SchemaBuilder.FromObject <TestSchema>();
            // Add a argument field with a require parameter
            var tree = new GraphQLCompiler(schemaProvider, new DefaultMethodProvider()).Compile(@"query {
                user(id: 1) { id }
            }").Operations.First();

            Assert.Single(tree.QueryFields);
            dynamic result = tree.Execute(new TestSchema(), new GraphQLValidator(), null);

            // we only have the fields requested
            Assert.Equal(1, result.user.GetType().GetFields().Length);
            Assert.Equal("id", result.user.GetType().GetFields()[0].Name);
            Assert.Equal(1, result.user.id);
        }
        public void SupportEntityQuery()
        {
            var schemaProvider = SchemaBuilder.FromObject <TestSchema>(false);

            schemaProvider.ReplaceField("users", new { filter = EntityQuery <User>() }, (ctx, p) => ctx.Users.Where(p.filter), "Return filtered users");
            var tree = new GraphQLCompiler(schemaProvider, new DefaultMethodProvider()).Compile(@"query {
	users(filter: ""field2 = ""2"" "") { field2 }
}").Operations.First();

            Assert.Single(tree.QueryFields);
            dynamic result = tree.Execute(new TestSchema(), new GraphQLValidator(), null);

            Assert.Equal(1, Enumerable.Count(result.users));
            var user = Enumerable.First(result.users);

            Assert.Equal("2", user.field2);
        }
        public void SupportsArgumentsDefaultValue()
        {
            var schemaProvider = SchemaBuilder.FromObject <TestSchema>();

            // Add a argument field with a default parameter
            schemaProvider.AddField("me", new { id = 9 }, (ctx, param) => ctx.Users.Where(u => u.Id == param.id).FirstOrDefault(), "Return me, or someone else");
            var tree = new GraphQLCompiler(schemaProvider, new DefaultMethodProvider()).Compile(@"query {
                me { id }
            }").Operations.First();

            Assert.Single(tree.QueryFields);
            dynamic result = tree.Execute(new TestSchema(), null);

            // we only have the fields requested
            Assert.Equal(1, result.me.GetType().GetFields().Length);
            Assert.Equal("id", result.me.GetType().GetFields()[0].Name);
            Assert.Equal(9, result.me.id);
        }
        public void SupportsArguments()
        {
            var schemaProvider = SchemaBuilder.FromObject <TestSchema>(false);

            // Add a argument field with a require parameter
            schemaProvider.AddField("user", new { id = Required <int>() }, (ctx, param) => ctx.Users.Where(u => u.Id == param.id).FirstOrDefault(), "Return a user by ID");
            var tree = new GraphQLCompiler(schemaProvider, new DefaultMethodProvider()).Compile(@"query {
	user(id: 1) { id }
}").Operations.First();

            // db => db.Users.Where(u => u.Id == id).Select(u => new {id = u.Id}]).FirstOrDefault()
            Assert.Single(tree.QueryFields);
            dynamic result = tree.Execute(new TestSchema(), null);

            // we only have the fields requested
            Assert.Equal(1, result.user.GetType().GetFields().Length);
            Assert.Equal("id", result.user.GetType().GetFields()[0].Name);
            Assert.Equal(1, result.user.id);
        }