Skip to content
/ ubeer Public

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

License

Notifications You must be signed in to change notification settings

astorije/ubeer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published