Skip to content

Is it possible to return a ResponseEntity<T> from a resolver #588

Description

@naveen4801

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions