Это простая схема, где поле c зависит от идентификатора B
Код: Выделить всё
type A {
id: Int!
b: [B]
}
type B {
id: Int!
с: C
}
type C {
с: C //depends on id type B
}
Код: Выделить всё
@QueryMapping
public A getA(DataFetchingEnvironment environment) {
A a = repo.getA();
int index = 0;
for (B b : a.getB()) {
environment.getGraphQlContext().put(index, b.getId());
index++;
}
return A;
}
@SchemaMapping(field = "c", typeName = "C")
public C getC(DataFetchingEnvironment environment) {
Integer currentIndex = environment.getExecutionStepInfo().getParent().getParent().getPath().getSegmentIndex();
C c = repo2.getC(environment.getGraphQlContext().get(currentIndex));
return c;
}
В SchemaMapping у меня есть только Тип C и я не могу получить Тип B , поэтому я использую GraphQlContext.
Могу ли я получить родительские значения (Тип B) из DataFetchingEnvironment без использования GraphQlContext?
Я использую GraphQlContext, но не уверен, что это лучшее решение
Подробнее здесь: https://stackoverflow.com/questions/790 ... nvironment
Мобильная версия