🍻 Ubeer is a stupidly simple application to demonstrate the capabilities of GraphQL in Scala using Sangria and Akka HTTP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
graphiql
project
screenshots
src/main
ubeer-client
.gitignore
.java-version
LICENSE
README.md
build.sbt

README.md

Ubeer

Ubeer is a very simple client-server application where:

  • The server exposes a GraphQL endpoint using Sangria and Akka HTTP.
  • The client is a Vanilla JS application to locate breweries around you.

It was developed for a lightning talk I gave at NE Scala NYC 2017 on 24 March 2017. The slides of this talk can be found at https://astori.fr/graphql-nescala.

screen shot 2017-08-10 at 01 42 35
Watch the talk


The Ubeer client       GraphiQL
The Ubeer client & GraphiQL

Client-Server architecture
Data model
Backend architecture

Running the project

In your console, run:

sbt run

This will compile the project, load the JSON files in memory, print the GraphQL schema in the console and start the Akka HTTP server.

Once the server is started you can:

Query examples

The following examples illustrate some capabilities GraphQL offers on this project.

Running these from the links given below assumes that you are running this project locally (see above).

Arguments

Run this example

{
  beer(id: 360) {
    name
    description(charLimit: 50)
  }
}

More information about arguments

Aliases

Run this example

{
  beerOne: beer(id: 360) {
    name
  }
  beerTwo: beer(id: 440) {
    name
  }
}

More information about aliases

Reusable fragments

Run this example

{
  beerOne: beer(id: 360) {
    ...beerSummary
  }
  beerTwo: beer(id: 440) {
    ...beerSummary
  }
}

fragment beerSummary on Beer {
  name
  brewery {
    name
  }
}

More information about fragments

Variables

Run this example

query ($city: String) {
  breweries(city: $city) {
    name
    address
    website
  }
}

And in the Query variables tab:

{
  "city": "Brooklyn"
}

More information about variables

Directives

Run this example

query ($skipBeers: Boolean!) {
  breweries {
    name
    address
    website
    beers @skip(if: $skipBeers) {
      name
      abv
    }
  }
}

And in the Query variables tab:

{
  "skipBeers": false
}

More information about directives

Introspection

Run this example

{
  __schema {
    types {
      kind
      name
      description
    }
  }

  __type(name: "Beer") {
    kind
    name
    description
    fields {
      name
      type {
        kind
        name
        ofType {
          name
        }
      }
      args {
        name
        type {
          kind
          name
        }
      }
    }
  }
}

More information about introspection

About the data

The JSON data files come from the Open Beer Database project, converted from CSV to JSON (with some cleanup and reformatting along the way) using this tool.

Thanks to them for making these available!

However, note that data in these files is dated from 2011, and I had to delete more than half the beers whenever they were lacking a style, a brewery, etc. If anyone knows of a more up-to-date and sanitized list of beers and breweries, let me know!