Introducing the WildFly MicroProfile GraphQL Feature Pack

I am pleased to announce the 1.0.0.Beta1 release of the MicroProfile GraphQL feature pack for WildFly. It offers experimental support for the MicroProfile GraphQL 1.0 specification, implemented by SmallRye GraphQL.

The source code for the feature pack can be found on GitHub.

Installing the feature pack

For now, the GraphQL support is distributed as a feature pack rather than integrated into WildFly itself.

To install the feature pack, download the latest version of Galleon. At the time of writing this is 4.2.5. Unzip it somewhere, and add its bin/ folder to your path.

Next, save a copy of provision.xml somewhere, and go to that folder in a terminal window. Then run:

$galleon.sh provision ./provision.xml --dir=my-wildfly

This will take some time the first time you do it since it will download a lot of dependencies from Maven. Once that is done, subsequent attempts will be fast.

What this command does is:

  • Provision a slimmed version (compared to the full download) of WildFly containing the relevant parts for a server running in the cloud. The main README of the project repository contains more information about this part. You can adjust this file to choose other parts of the server you may be interested in.

  • Next it provisions the full contents of the feature pack into our new server instance.

  • The provisioned server will be output in the my-wildfly subdirectory, and can be started via the usual my-wildfly/bin/standalone.sh command.

Example

A very short example of what you can do with GraphQL is as follows. This is inspired by the quickstart (included in the GitHub repository containing the feature pack), so be sure to try it out!

Here we will just show you how to create an endpoint that returns data from a database of Star Wars films, namely just the operation that retrieves information about all films in the database:

@GraphQLApi
public class FilmResource {

    @Inject
    GalaxyService service;

    @Query("allFilms")
    @Description("Get all Films from a galaxy far far away")
    public List<Film> getAllFilms() {
        return service.getAllFilms();
    }
}

The Film class is just a regular JavaBean (getters and setters omitted for brevity):

public class Film {
    private String title;
    private Integer episodeID;
    private String director;
    private LocalDate releaseDate;
}

In such case, if the GraphQL client calls the following query:

query allFilms {
  allFilms {
    title
    releaseDate
  }
}

The client will get back the requested data about all the films in the database (in our case, we only included episodes 4, 5 and 6!):

{
  "data": {
    "allFilms": [
      {
        "title": "A New Hope",
        "releaseDate": "1977-05-25"
      },
      {
        "title": "The Empire Strikes Back",
        "releaseDate": "1980-05-21"
      },
      {
        "title": "Return Of The Jedi",
        "releaseDate": "1983-05-25"
      }
    ]
  }
}

Feedback

We’re keen to hear your feedback! Please raise any issues found at https://github.com/wildfly-extras/wildfly-graphql-feature-pack/issues.