Is it possible to return a ResponseEntity<T> from a resolver #589
Replies: 4 comments
-
No that is not possible. Could you elaborate why returning The only other type that is supported as a return value is |
Beta Was this translation helpful? Give feedback.
-
Currently We are migrating REST services into GraphQL , Since we were retrieving errors and responses in ResponseEntity type from AOP, so it will be more flexible to get response from GraghQL in ResponposeEntity type |
Beta Was this translation helpful? Give feedback.
-
can you please elaborate how can i change this into a DataFetcherResult from ResponseEntity |
Beta Was this translation helpful? Give feedback.
-
public DataFetcherResult<SomeData> getUserById(){
return DataFetcherResult.newResult().data(data).error(error).build();
} |
Beta Was this translation helpful? Give feedback.
-
I'm using graphql-java with spring boot.
My schema looks like this.
type Query{
userById(id: String): User
}
type User {
id: String
name: String
email: String
}
I have a QueryResolver class that implements GraphQLQueryResolver. My get method inside this class looks like this.
public User getUserById(String id) {
return someClient.getUserById(id).getBody(); //getUserById inside someClient returns a ResponseEntity
}
What I need inside my QueryResolver is to return a ResponseEntity instead of a User. So it'll look like the code below
public ResponseEntity getUserById(String id) {
return someClient.getUserById(id);
}
The above code returns a schema error saying org.springframework.http.ResponseEntity cannot be mapped to a GraphQL type! Since GraphQL-Java deals with erased types at runtime, only non-parameterized classes can represent a GraphQL type. What does this mean? Is it possible to return a ResponseEntity<> from a resolver?
Beta Was this translation helpful? Give feedback.
All reactions