-
Notifications
You must be signed in to change notification settings - Fork 2
/
GraphQLEndpoint.java
35 lines (30 loc) · 1.16 KB
/
GraphQLEndpoint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.mapr.music.api.graphql;
import com.mapr.music.api.graphql.errors.GraphQLErrorWrapper;
import com.mapr.music.api.graphql.schema.GraphQLSchemaProvider;
import graphql.ExceptionWhileDataFetching;
import graphql.GraphQLError;
import graphql.servlet.DefaultGraphQLErrorHandler;
import graphql.servlet.GraphQLErrorHandler;
import graphql.servlet.SimpleGraphQLServlet;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
public class GraphQLEndpoint extends SimpleGraphQLServlet {
@Inject
public GraphQLEndpoint(GraphQLSchemaProvider schemaProvider) {
super(schemaProvider.schema());
}
@Override
protected GraphQLErrorHandler getGraphQLErrorHandler() {
return new DefaultGraphQLErrorHandler() {
@Override
protected List<GraphQLError> filterGraphQLErrors(List<GraphQLError> errors) {
return errors.stream()
.filter(e -> e instanceof ExceptionWhileDataFetching || super.isClientError(e))
.map(e -> e instanceof ExceptionWhileDataFetching ? new GraphQLErrorWrapper((ExceptionWhileDataFetching) e)
: e)
.collect(Collectors.toList());
}
};
}
}