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
- Host: GitHub
- URL: https://github.com/astorije/ubeer
- Owner: astorije
- License: mit
- Created: 2017-03-12T20:39:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-10T05:48:00.000Z (almost 9 years ago)
- Last Synced: 2025-04-15T13:09:25.706Z (about 1 year ago)
- Topics: akka-http, beer, graphql, sangria
- Language: CSS
- Homepage: https://astori.fr/graphql-nescala
- Size: 4.32 MB
- Stars: 13
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 .
The Ubeer client & GraphiQL
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
```graphql
{
beer(id: 360) {
name
description(charLimit: 50)
}
}
```
[More information about arguments](http://graphql.org/learn/queries/#arguments)
### Aliases
```graphql
{
beerOne: beer(id: 360) {
name
}
beerTwo: beer(id: 440) {
name
}
}
```
[More information about aliases](http://graphql.org/learn/queries/#aliases)
### Reusable fragments
```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
```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
```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
```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!