I am having 5 rest API's(java) with different endpoint URL,and each have different request,response format.So I have combined them as a single API with a common JSON complex request and response as a key value pair structure.
Now T found recently about GraphQL and interested to fit it in my requirement, I have done analysis on that and want to know how well I Could implement some of my questions:
1) Can we implement complex rest API service(post) in GRAPHQL?(while googling,got only for simple get method.Also is there only for node/javascript)
GraphQL is a cross-platform, open-source, data query, and manipulation language for APIs. GraphQL servers are available for multiple languages such as Java, Python, C#, PHP, R, Haskell, JavaScript, Perl, Ruby, Scala, Go, Elixir, Erlang, and Clojure, etc. So, it can be used with any programming language and framework.
GraphQL can be overkill Since GraphQL is so complex and powerful, it can commonly be overkill for smaller applications. If you have a simple/straight-forward app in front of you, it will be easier to work with a REST API.
The core difference between GraphQL and REST APIs is that GraphQL is a specification, a query language, while REST is an architectural concept for network-based software.
As previously mentioned, GraphQL does not replace REST. Despite their differences, GraphQL and REST also have similarities: They can both be fetched by an HTTP GET request with a URL and return the request in JSON data. GraphQL and REST allow the specification of IDs for resources.
1) Can we implement complex rest API service(post) in GRAPHQL?(while googling,got only for simple get method.Also is there only for node/javascript)
Since you say you did your analysis about GraphQL, I'm assuming that by "implement complex REST API server (POST) in GraphQL", you meant how you can expose the functionality of REST API through GraphQL. Yes, you can do that by using GraphQL mutations. In your mutation implementation (resolve function), you'll invoke the REST POST operations.
swapi-graphql is an interesting project that wraps Star Wars REST API.
2) Is there any framework for java based graphQL implementation?
Check out Java section of awesome-graphql. The Java GraphQL library doesn't seem to be well-maintained though.
Question 1) is answered in the other answer.
Question 2) Java Implementation:
Sample Code:
public class HelloWorld {
public static void main(String[] args) {
GraphQLObjectType queryType = newObject()
.name("helloWorldQuery")
.field(newFieldDefinition()
.type(GraphQLString)
.name("hello")
.staticValue("world"))
.build();
GraphQLSchema schema = GraphQLSchema.newSchema()
.query(queryType)
.build();
GraphQL graphQL = GraphQL.newGraphQL(schema).build();
Map<String, Object> result = graphQL.execute("{hello}").getData();
System.out.println(result);
// Prints: {hello=world}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With