我是新来GraphQL,我周围使用GraphQL API graphql-java的servlet封装。我不能够覆盖GraphQLErrorHandler和我SimpleGraphQLHttpServlet总是在前端返回Internal 500 Error
。
我试图总结在graphql servlet的自定义错误
我终于想通了我自己。我们必须使用GraphQLObjectMapper
建设者,并添加它实现GraphQLErrorHandler界面的自定义错误包装和实施processErrors(List<GraphQL> error)
方法。
GraphQLObjectMapper mapper = GraphQLObjectMapper.newBuilder()
.withGraphQLErrorHandler(customErrorHandlerObject).build();
SimpleGraphQLHttpServlet graphQLServlet = SimpleGraphQLHttpServlet.newBuilder(ciBridgeGraphQLSchemaProvider)
.withObjectMapper(mapper).build();