GraphQL implementation Java

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:

  • graphql-java is a Java implementation for GraphQL.
  • graphql-java-annotations is a Java Library build on graphql-java.

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}
    }
}

Tags:

Java

Rest

Graphql