Git Product home page Git Product logo

sangria-akka-http-example's Introduction

Sangria akka-http Example

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

Deploy

After starting the server with

sbt run

# or, if you want to watch the source code changes
 
sbt ~reStart

you can run queries interactively using graphql-playground by opening http://localhost:8080 in a browser or query the /graphql endpoint directly. The HTTP endpoint follows GraphQL best practices for handling the HTTP requests.

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-example's People

Contributors

andyczerwonka avatar jonas avatar lvitaly avatar nickhudkins avatar olegilyenko avatar rayyildiz avatar scala-steward avatar sh0hei avatar yanns avatar yoshinorin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sangria-akka-http-example's Issues

Server shutting down after 3 seconds

Hello! After cloning & running the project as is I cant get it to run as expected, server seems to shut down after 3 seconds without an error ๐Ÿ˜•

โžœ  sangria-akka-http-example git:(main) โœ— sbt run
[info] welcome to sbt 1.8.2 (AdoptOpenJDK Java 16.0.1)
[info] loading global plugins from /Users/karleriksson/.sbt/1.0/plugins
[info] loading settings for project sangria-akka-http-example-build-build-build from metals.sbt ...
[info] loading project definition from /Users/karleriksson/trams/scala/sbttest/sangria-akka-http-example/project/project/project
[info] loading settings for project sangria-akka-http-example-build-build from metals.sbt ...
[info] loading project definition from /Users/karleriksson/trams/scala/sbttest/sangria-akka-http-example/project/project
[success] Generated .bloop/sangria-akka-http-example-build-build.json
[success] Total time: 1 s, completed 9 Mar 2023, 20:48:46
[info] loading settings for project sangria-akka-http-example-build from metals.sbt,plugins.sbt ...
[info] loading project definition from /Users/karleriksson/trams/scala/sbttest/sangria-akka-http-example/project
[success] Generated .bloop/sangria-akka-http-example-build.json
[success] Total time: 1 s, completed 9 Mar 2023, 20:48:47
[info] loading settings for project sangria-akka-http-example from build.sbt ...
[info] set current project to sangria-akka-http-example (in build file:/Users/karleriksson/trams/scala/sbttest/sangria-akka-http-example/)
[info] running Server
[success] Total time: 3 s, completed 9 Mar 2023, 20:48:51

Extracting this into a library

Hi,

has anyone ever considered extracting the boilerplate code into a library?

it would be neat to do

libraryDependencies += "org.sangria-graphql"    %% "sangria-akka-http"               % sangriaVersion

route = 
  graphQLPlayground ~
  prepareGraphQLRequest(...)

It would cut down on the boilerplate and make the adoption of graphql in Scala even simpler.

Of course, implementations for other http server libraries could be made as needed.

Activator template out of date

I think the activator template is out of date with this project. When I download it, the build.sbt is using version 0.5.1 of the sangria project.

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.