An open API service indexing awesome lists of open source software.

https://github.com/astorije/ubeer

🍻 Ubeer is a stupidly simple application to demonstrate the capabilities of GraphQL in Scala using Sangria and Akka HTTP
https://github.com/astorije/ubeer

akka-http beer graphql sangria

Last synced: about 1 year ago
JSON representation

🍻 Ubeer is a stupidly simple application to demonstrate the capabilities of GraphQL in Scala using Sangria and Akka HTTP

Awesome Lists containing this project

README

          

# Ubeer

Ubeer is a very simple client-server application where:

- The server exposes a [GraphQL](http://graphql.org/) endpoint using [Sangria](http://sangria-graphql.org/) 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](http://www.nescala.org/) on 24 March 2017. The slides of
this talk can be found at .



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:

```sh
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 .
- Run queries interactively using [GraphiQL](https://github.com/graphql/graphiql)
at (see below for some examples).

## 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

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

[More information about arguments](http://graphql.org/learn/queries/#arguments)

### Aliases

Run this example

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

[More information about aliases](http://graphql.org/learn/queries/#aliases)

### Reusable fragments

Run this example

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

fragment beerSummary on Beer {
name
brewery {
name
}
}
```

[More information about fragments](http://graphql.org/learn/queries/#fragments)

### Variables

Run this example

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

And in the *Query variables* tab:

```json
{
"city": "Brooklyn"
}
```

[More information about variables](http://graphql.org/learn/queries/#variables)

### Directives

Run this example

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

And in the *Query variables* tab:

```json
{
"skipBeers": false
}
```

[More information about directives](http://graphql.org/learn/queries/#directives)

### Introspection

Run this example

```graphql
{
__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](http://graphql.org/learn/introspection/)

## About the data

The [JSON data files](https://github.com/astorije/ubeer/tree/master/src/main/resources)
come from the [Open Beer Database](https://openbeerdb.com/) project, converted
from CSV to JSON (with some cleanup and reformatting along the way) using
[this tool](http://www.convertcsv.com/csv-to-json.htm).

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!