I have a project where I try to map REST api to GraphQL. I have implemented Camel to connect to vide veriaty of microservices via rest, based on graphql query (so basicly my project functions like translator – request comes via graphql and is passed to rest service). I’m using spring-boot, graphql-spqr-spring-boot-starter (0.0.7) and spring-camel (3.14) for that.
I’m connecting 2 worlds with Service as follows:
@Service
@GraphQLApi
public class GraphQLAPIService
{
private final ProducerTemplate producerTemplate;
public GraphQLAPIService(ProducerTemplate producerTemplate)
{
this.producerTemplate = producerTemplate;
}
@GraphQLQuery(name = "getInfo")
public LoginInfo[] getInfo(@GraphQLArgument(name = "name") String name, @GraphQLArgument(name = "nick") String nick) {
final Map<String, Object> headers = new HashMap<String, Object>() {{
put("name", name);
put("nick", nick);
}};
return producerTemplate.requestBodyAndHeaders("direct:getInfo",null, headers, ResponseInfo[].class);
}
Now I’m trying to add to do 2 things:
-
Modify standard error, because the current a lot of information (example below). I would like to remove f.ex. locations:
{ "errors": [ { "message": "Exception while fetching data (/getInfo) : Exception occurred during execution on the exchange: Exchange[AFA581764D6BE82-0000000000000000]", "locations": [ { "line": 2, "column": 5 } ], "path": [ "getInfo" ], "extensions": { "classification": "DataFetchingException" } } ], "data": {
-
I would like to add “warning” section, where I will put additional info. Like f. ex. when I’ve got 404 from resource, it will be not treated like error, but just add warning that response was empty.
What I’ve tried so far:
-
Implement custom GraphQLExecutor like follows:
public class MyGraphQLExecutor extends HttpExecutor<NativeWebRequest> implements GraphQLMvcExecutor { protected MyGraphQLExecutor (ContextFactory<NativeWebRequest> contextFactory, DataLoaderRegistryFactory dataLoaderRegistryFactory) { super(contextFactory, dataLoaderRegistryFactory); } @Override public Object execute(GraphQL graphQL, ExecutorParams<NativeWebRequest> executorParams) { Object object = super.execute(graphQL, executorParams); return object; } }
But the “object” which is response is already made so, that I cannot modify it.
- Tried to add my own
ResolverInterceptor
and create custom exceptions, but I couldn’t make this work too.
Both thins didn’t help me with my 2 issues.