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.
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:
- Play with the client app at http://localhost:8080/ubeer/index.html.
- Run queries interactively using GraphiQL at http://localhost:8080/graphiql/index.html (see below for some 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).
{
beer(id: 360) {
name
description(charLimit: 50)
}
}
More information about arguments
{
beerOne: beer(id: 360) {
name
}
beerTwo: beer(id: 440) {
name
}
}
More information about aliases
{
beerOne: beer(id: 360) {
...beerSummary
}
beerTwo: beer(id: 440) {
...beerSummary
}
}
fragment beerSummary on Beer {
name
brewery {
name
}
}
More information about fragments
query ($city: String) {
breweries(city: $city) {
name
address
website
}
}
And in the Query variables tab:
{
"city": "Brooklyn"
}
More information about variables
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
{
__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
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!