Skip to content

Baosight-plat/sangria-akka-http-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sangria akka-http Example

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

Deploy

After starting the server with

sbt run

you can query /graphql endpoint. It accepts following properties in the JSON body (this follows relay convention):

  • query - String - GraphQL query as a string
  • variables - String - containing JSON object that defines variables for your query (optional)
  • operation - String - the name of the operation, in case you defined several of them in the query (optional)

Here are some examples of the queries you can make:

$ curl -X POST localhost:8080/graphql \
    -H "Content-Type:application/json" \
    -d '{"query": "{hero {name, friends {name}}}"}'

this gives back the hero of StarWars Saga together with the list of his friends, which is of course R2-D2:

{
  "data": {
    "hero": {
      "name": "R2-D2",
      "friends": [
        {
          "name": "Luke Skywalker"
        },
        {
          "name": "Han Solo"
        },
        {
          "name": "Leia Organa"
        }
      ]
    }
  }
}

Here is another example, which uses variables:

$ curl -X POST localhost:8080/graphql \
    -H "Content-Type:application/json" \
    -d '{"query": "query Test($humanId: String!){human(id: $humanId) {name, homePlanet, friends {name}}}", "variables": "{\"humanId\": \"1000\"}"}'

The result should be something like this:

{
  "data": {
    "human": {
      "name": "Luke Skywalker",
      "homePlanet": "Tatooine",
      "friends": [
        {
          "name": "Han Solo"
        },
        {
          "name": "Leia Organa"
        },
        {
          "name": "C-3PO"
        },
        {
          "name": "R2-D2"
        }
      ]
    }
  }
}

About

An example GraphQL server written with akka-http and sangria

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 100.0%