Skip to content
Branch: master
Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
project
src Updated to sangria v1.1.0 Mar 11, 2017
.gitignore Added Scala example using Sangria May 6, 2016
README.md
build.sbt

README.md

Scala Example

An example Scala GraphQL server written with akka-http and sangria.

Prerequisites

Running the example

sbt ~reStart

SBT will automatically compile and restart the server whenever the source code changes.

After the server is started you can run queries interactively using GraphiQL by opening http://localhost:8080 in a browser.

Database Configuration

This example uses an in-memory H2 SQL database. The schema and example data will be re-created every time server starts.

If you would like to change the database configuration or use a different database, then please update src/main/resources/application.conf.

Deferred values

Queries like this one:

query AllPeopleWithFriends {
  allPeople {
    fullName
    friends {
      firstName
      lastName
    }
  }
}

…may result in N+1 database queries since the friends field is fetched for every person in a list. In order to solve this problem, the example uses deferred values: the friends field returns a FriendsDeferred instance which is then given to FriendsResolver by the execution engine, enabling it to batch friend queries.

Protection against malicious queries

Due to the recursive nature of the GraphQL schema, it's possible for a client to send infinitely deep friends queries. As a safety measure, this example uses query complexity analysis and rejects all queries above a complexity threshold (300 by default).

You can’t perform that action at this time.