Can somebody please explain me how to wrap existing REST API in graphql, and how it will improve the performance ?
Any small working example would help a lot.
Thanks in advance !!!
Can somebody please explain me how to wrap existing REST API in graphql, and how it will improve the performance ?
Any small working example would help a lot.
Thanks in advance !!!
Define the Query/Mutation in GraphQL schema.
type Query {
getBook(id: String): Book
}
Inside the Query resolver class use any method to consume rest service.
public class Query implements GraphQLQueryResolver {
public Book getBook(String bookId) {
RestTemplate restTemplate = new RestTemplate();
Map<String, String> map = new HashMap<>();
map.put("bookId", bookId);
ResponseEntity <Book> response = restTemplate.getForEntity("http://localhost:8080/bookDetails/getBook/{bookId}",Book.class, map);
Book book = response.getBody();
return book;
}
}
In the same way you can define Mutation also by implementing GraphQLMutationResolver.