Код: Выделить всё
@Controller
public class HelloNameController {
@QueryMapping
public String hello(@Argument String name) {
return "Hello " + name;
}
}
Схема Graphql
Код: Выделить всё
type Query {
hello (name : String!) : String
}
В официальной документации сказано реализовать DataFetcherExceptionResolverAdapter, и я реализовал его как bean-компонент
Код: Выделить всё
@Configuration
public class GraphQLConfig {
@Bean
public DataFetcherExceptionResolver exceptionResolver() {
return DataFetcherExceptionResolverAdapter.from((ex, env) -> {
if (ex instanceof CoercingParseValueException) {
return GraphqlErrorBuilder.newError(env).message("CoercingParseValueException")
.errorType(ErrorType.ExecutionAborted).build();
}
if (ex instanceof CoercingSerializeException) {
return GraphqlErrorBuilder.newError(env).message("CoercingSerializeException")
.errorType(ErrorType.ExecutionAborted).build();
} else {
return null;
}
});
}
}
Подробнее здесь: https://stackoverflow.com/questions/725 ... pring-boot
Мобильная версия