Skip to content

UseFilter referencing a service field in the filter arg fails #303

@lukemurray

Description

@lukemurray

Repro

[Fact]
        public void TestOffsetPagingWithOthersAndServices()
        {
            var schema = SchemaBuilder.FromObject<TestDataContext>();
            var data = new TestDataContext();
            data.People.Add(new Person { Id = 1, Name = "Jill", LastName = "Frank", Birthday = DateTime.Now.AddYears(22) });
            data.People.Add(new Person { Id = 2, Name = "Cheryl", LastName = "Frank", Birthday = DateTime.Now.AddYears(10) });

            schema.Query().ReplaceField("people", ctx => ctx.People, "Return list of people")
                .UseFilter();
            schema.Type<Person>().AddField("age", "Persons age")
                .ResolveWithService<AgeService>((person, ager) => ager.GetAge(person.Birthday));
            var gql = new QueryRequest
            {
                Query = @"{
                    people(filter: ""age > 21"") {
                        name id age lastName
                    }
                }",
            };

            var serviceCollection = new ServiceCollection();
            var ager = new AgeService();
            serviceCollection.AddSingleton(ager);

            var result = schema.ExecuteRequest(gql, data, serviceCollection.BuildServiceProvider(), null);
            Assert.Null(result.Errors);

            dynamic people = result.Data["people"];
            Assert.Equal(1, Enumerable.Count(people));
            var person1 = Enumerable.ElementAt(people, 0);
            Assert.Equal("Frank", person1.lastName);
            Assert.Equal("Jill", person1.name);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions