Relay.js-compatible GraphQL adaptor for ES4J
Clone or download
Latest commit deb837b Nov 25, 2016

Maven Central

ES4J (Eventsourcing for Java) GraphQL adaptor

This module implements a Relay.js-compatible GraphQL server intended to be used with ES4J commands. It also supports OSGi out of the box.


You can download es4j-graphql from bintray (Gradle syntax):

repositories {

dependencies {
  compile 'com.eventsourcing:eventsourcing-graphql:0.4.5'


The are a few important components this package provides (some of them come from graphql-java-servlet):

  • GraphQLQueryProvider/GraphQLMutationProvider interfaces. These will allow you to define which "domain model" views and which commands you are going to expose.
  • GraphQLServlet as an entry point servlet. Use bindQueryProvider/bindMutationProvider i or automatically wire them in OSGi.

Commands as mutations

@Accessors(fluent = true)
public static class TestCommand extends StandardCommand<Void, String> {
    private String value;

There are two ways to expose such commands, one is to use PackageGrapgQLMutationProvider to scan all relevant packages to find subclasses of GraphQLCommand in those packages. For OSGi environments, BundleGraphQLMutationProvider should be used to scan relevant bundles.

Domain models as queries

public static class TestQueryProvider implements GraphQLQueryProvider {

    public static class TestObject {
        public String field;

    @Override @SneakyThrows
    public GraphQLObjectType getQuery() {
        return GraphQLAnnotations.object(Query.class);

    public Object context() {
        return new Query();

Since it implements GraphQLQueryProvider, it can be bound to the servlet and will be automatically exposed as testObject { field }