You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a simple class that I want to expose via graphQL.
@Document(collection = "question")
public class Question {
private String label;
}
I managed to expose it using a controller
@Controller
public class QuestionController {
private final QuestionRepository questionRepository;
public QuestionController(QuestionRepository questionRepository) {
this.questionRepository = questionRepository;
}
@QueryMapping
public Window<Question> allQuestions() {
return questionRepository.findAllBy(ScrollPosition.offset());
}
}
with schema
type Query {
allQuestions: QuestionConnection
}
type Question {
label: String
}
The next step is to expose all questions, along with possible tags (like search faceting). The questions should be paginated.
I created a wrapper class
public class WrappedQuestion {
private Window<Question> questions;
private List<String> tags;
}
Add a query mapping
@QueryMapping
public WrappedQuestion allQuestionsWithWrapper() {
WrappedQuestion wrappedQuestion = new WrappedQuestion();
wrappedQuestion.setQuestions(questionRepository.findAllBy(ScrollPosition.offset()));
wrappedQuestion.setTags(List.of("Spring", "GraphQL"));
return wrappedQuestion;
}
and its types
type Query {
allQuestionsWithWrapper: WrappedQuestion
}
type WrappedQuestion {
questions: QuestionConnection
tags: [String]
}
When I run the following query, I got an error for the questions field:
{
"errors": [
{
"message": "The field at path '/allQuestionsWithWrapper/questions/edges' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value. The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is '[QuestionEdge]' within parent type 'QuestionConnection'",
"path": [
"allQuestionsWithWrapper",
"questions",
"edges"
],
"extensions": {
"classification": "NullValueInNonNullableField"
}
}
],
"data": {
"allQuestionsWithWrapper": {
"tags": [
"Spring",
"GraphQL"
]
}
}
}
The same query without wrapping works and returns data
I have a simple class that I want to expose via graphQL.
I managed to expose it using a controller
with schema
The next step is to expose all questions, along with possible tags (like search faceting). The questions should be paginated.
I created a wrapper class
Add a query mapping
and its types
When I run the following query, I got an error for the questions field:
The same query without wrapping works and returns data
The text was updated successfully, but these errors were encountered: