Coder Social home page Coder Social logo

sangria-akka-http-cassandra's Introduction

Sangria akka-http Cassandra Example

Note: Inspired from Oleg Ilyenko's original repo where Oleg demonstrated how Sangria can be integrated with Akka Http which the GQL can be offered as a service.

This repo simply rides ontop of that by demonstrating how the querying can be lifted from Cassandra. Caution : this example is for demonstration purposes only.

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

Deploy

After starting the server with

sbt run

you can run queries interactively using GraphiQL by opening http://localhost:8080 in a browser or query the /graphql endpoint. It accepts following properties in the JSON body (this follows relay convention):

  • query - String - GraphQL query as a string
  • variables - Object or String containing a JSON object that defines variables for your query (optional)
  • operationName - 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"
        }
      ]
    }
  }
}

sangria-akka-http-cassandra's People

Contributors

andyczerwonka avatar jonas avatar olegilyenko avatar raymondtay avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.