Skip to content

doyleyoung/vertx-graphql-example

Repository files navigation

Vert.x GraphQL Example

VG

When it comes to performance and scalability, Vert.x has always been hard to beat and version 3 just made it much easier to develop and deploy.

This simple application is used to demonstrate:

  • that Java CompletableFuture, Vert.x Futures and RxJava can be easily combined
  • that Vert.x micro-services are easy to develop and deploy through Docker containers

The goal of this application is to exercise graphql-java async (non-blocking) with Vert.x.

In addition it also uses:

  • graphql-apigen - to facilitate the graphql schema generation
  • vertx-dataloader - to ensure a consistent API data fetching between the different resources

System Architecture

                    .---------.       .-----------.
  POST /graphql --> | GraphQL |       | Customer  |
                    | Service | ----> | Service   |
                    '---------'   |   '-----------'
                                  |   .-----------.   
                                  |   | Vehicle   |
                                  |-> | Service   |
                                  |   '-----------'
                                  |   .-----------.
                                  |   | Rental    |
                                  '-> | Service   |
                                      '-----------'

Before you start

graphql-java-async is not out yet. In order to build this project you need to:

  1. graphql-java - Checkout and build Dmitry's async branch
  2. graphql-apigen - Checkout and build the eb_graphql branch of my fork of Distelli/graphql-apigen

Build:

After building the async branches of both graphql-java and graphql-apigen do:

mvn clean package

Execute:

./docker/run.sh

Test

The graphql-service exposes a POST endpoint. You can use CURL but it is recommended to use Graphiql App.

Sample queries to use on a POST to http://localhost:8080/graphql.

Querying for a single rental entry:

{
  rental(id: 1) {
    id
    customer {
      id
      name
      address
      city
      state
      country
      contact {
        phone
        type
      }
    }
    vehicle {
      id
      brand
      model
      type
      year
      mileage
      extras
    }
  }
}

Querying for all active rentals:

{
  rentals {
    id
    customer {
      id
      name
      address
      city
      state
      country
      contact {
        phone
        type
      }
    }
    vehicle {
      id
      brand
      model
      type
      year
      mileage
      extras
    }
  }
}

Example using CURL:

curl -k -X POST -d '{ "operationName": null, "query": "{ rentals { customer { name } vehicle { brand model } } }", "variables": "{}" }' http://localhost:8080/graphql

About

GraphQL Async example using Vert.x

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published