Skip to content

deontaljaard/http4s-sangria-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http4s-sangria-mongo

A reference project intended to be a starting point (reference) to use Sangria, a Scala implementation of the GraphQL specification.

Note: If you're upgrading the http4s version, the changelog is invaluable.

Running the service

Directly on your host

In the root of the project, invoke the following command:

sbt service/run

Using docker (assuming it's set up on your host)

In the root of the project, invoke the following:

sbt dockerize

If you'd like to run a MongoDB instance, run the following:

docker run --name mongo -p 27017:27017 -d mongo

This should pull and run the latest mongo image.

Add the required DB and collections - have a look at reference.conf in model/src/main/resources.

Ensure mongodb-clients is installed

sudo apt install mongodb-clients

Use the sample documents provided in the repo to add data to the collections.

mongoimport --db persons --collection persons --file persons.json

Add a generated mongo id for a peson into the devices.json

mongoimport --db persons --collection devices --file devices.json

To start the http4s-mongo service container, run the following:

docker run --name http4s -d -p 8080:8080 --link mongo:mongo deontaljaard.github.io/service

This will link the mongo container to the http4s container. Note that the connection string changes in this case as a result of the --link flag. The connection string to mongo will change from:

mongodb://[user:pass@]localhost:27017

to this:

mongodb://[user:pass@]mongo:27017

Navigate to graphiql

In your favourite browser, navigate to the GraphiQL interface.

Some sample queries

query A {
  person(id:"") {
    id
    firstName
    registrationData {
      deviceUID
    }
    created
  }
}

query B {
  device(id:"1") {
    id
    deviceUID
    personId
    created
  }
}

query C {
  devices(id: "1") {
    id
    deviceUID
  }
}

About

A demo project using http4s, Sangria and MongoDB

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published