'The default type resolver could not find a suitable Java type for GraphQL type `ArrayList. Provide a @DgsTypeResolver.`
I have a java - Spring Boot project using graphql and DGS from netflix. I have the following query:
type Query {
ticketingHistory(ticketId: String): TicketingHistory
}
interface TicketingHistory {
ticketId: String
createdOn: String
}
type TicketingEmail implements TicketingHistory {
ticketId: String
createdOn: String
emailId: String
processInstanceId: String
createdBy: EmailCreatedBy
mailFrom: String
to: String
cc: String
bcc: String
messageId: String
messageInReplyTo: String
messageReferences: String
subject: String
messagePlain: String
messageHtml: String
}
type TicketingComment implements TicketingHistory {
ticketId: String
commentId: String
userId: String
createdOn: String
taskId: String
message: String
}
and the data fetcher:
@DgsComponent
@RequiredArgsConstructor
@Slf4j
public class TicketingHistoryDataFetcher {
private final EmailService emailService;
private final ProcessInstanceService processInstanceService;
@DgsQuery
public List<? extends TicketingHistory> ticketingHistory(@InputArgument String ticketId) {
List<TicketingHistory> ticketingHistories = new ArrayList<>();
final Set<Email> emails = emailService.findAll(ticketId);
final List<CommentDTO> comments = processInstanceService.getComments(ticketId);
emails.stream()
.filter(Objects::nonNull)
.forEach(email -> ticketingHistories.add(ticketingEmail(email)));
comments.stream()
.filter(Objects::nonNull)
.forEach(comment -> ticketingHistories.add(ticketingComment(comment, ticketId)));
ticketingHistories.sort(Comparator.comparing(TicketingHistory::getCreatedOn));
return ticketingHistories;
}
}
when calling it from postman and debugging it I can see that this query is called and I am getting the data but at the moment when it tries to return the list it is failing with:
com.netflix.graphql.dgs.exceptions.InvalidTypeResolverException: The default type resolver could not find a suitable Java type for GraphQL type `ArrayList. Provide a @DgsTypeResolver.`
Solution 1:[1]
It looks like Resolver is missing. Check if you have TicketingEmail and TicketingComment classes (Should be spelled the same as the type name as per the doc) Or you should have a resolver (refer to below doc for sample resolver). https://netflix.github.io/dgs/advanced/type-resolvers-for-abstract-types/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DharmanBot |