Я новичок в GraphQL .
В настоящее время у меня есть определение запроса, которое ищет студентов и их участников классов :
var studentsQueryArguments = new QueryArguments();
studentsQueryArguments.Add(new QueryArgument<ListGraphType<IntGraphType>> { Name = "ids", Description = "Student indexes." });
studentsQueryArguments.Add(new QueryArgument<RangeModelType<double?, double?>> {Name = "age", Description = "Age range of student."});
Field<ListGraphType<StudentType>>(
"students",
arguments: studentsQueryArguments,
resolve: context =>
{
var students = relationalDbContext.Students.AsQueryable();
var classes = relationalDbContext.Classes.AsQueryable();
var participatedClasses = relationalDbContext.StudentInClasses.AsQueryable();
var ids = context.GetArgument<List<int>>("ids");
var age = context.GetArgument<RangeModel<double?, double?>>("age");
if (ids != null)
students = students.Where(x => ids.Contains(x.Id));
if (age != null)
{
var from = age.From;
var to = age.To;
if (from != null)
students = students.Where(x => x.Age >= from);
if (to != null)
students = students.Where(x => x.Age <= to);
}
var results = (from student in students
select new StudentViewModel
{
Id = student.Id,
Age = student.Age,
FullName = student.FullName,
Photo = student.Photo,
Classes = from participatedClass in participatedClasses
from oClass in classes
where participatedClass.StudentId == student.Id &&
participatedClass.ClassId == oClass.Id
select new ClassViewModel
{
Id = oClass.Id,
ClosingHour = oClass.ClosingHour,
Name = oClass.Name,
OpeningHour = oClass.OpeningHour
}
});
return results;
});
В моем коде выше я присоединяюсь к Студент и Класс .
С запросом
{
students(ids: [1, 2, 3]) {
id
age
classes {
name
openingHour
closingHour
}
}
}
Учащиеся и их классы возвращаются. Это нормально.
Что мне нужно, так это когда я использую этот запрос:
{
students(ids: [1, 2, 3]) {
id
age
}
}
Мое приложение не присоединится Учащийся с Класс , и просто вернет Учащийся Только информация.
Возможно ли это?
Спасибо