GraphQL Java implementation

I have 5 rest APIs (java) with different endpoint URLs, and each of them has a different request, response format. Therefore, I combined them as one API with a common complex JSON request and response as the structure of a pair of key values.

Now T recently found about GraphQL and was interested to fit it in my requirement, I did an analysis on this and want to know how well I could fulfill some of my questions:

1) Can we implement a comprehensive service API service (post) in the GRAPHQL service? (while the search query received only for the simple get.Also method exists only for node / javascript)

2) is there any infrastructure for implementing a graphical language based on java?
+6
source share
2 answers

1) Can we implement a comprehensive service API (post) API for leisure in GRAPHQL? (while the search engine obtained only for the simple get.Also method exists only for node / javascript)

Since you say you did your GraphQL analysis, I assume that "by implementing the comprehensive REST API (POST) server in GraphQL", you mean how you can expose the functionality of the REST API through GraphQL. Yes, you can do this using GraphQL mutations. In your mutation implementation (permission function), you will invoke REST POST operations.

swapi-graphql is an interesting project that wraps the Star Wars REST API .

2) Is there any infrastructure for implementing in Java based on java?

Check out the Java awesome-graphql section . However, the Java GraphQL library is not supported.

+8
source

Question 1) answered a different answer.

Question 2) Java implementation:

Code example:

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} } } 
+3
source

All Articles