GithubHelp home page GithubHelp logo

olegilyenko / sangria-tcp-msgpack-example Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 0.0 10 KB

An example TCP GraphQL server that uses a binary data format (MessagePack)

License: Apache License 2.0

Scala 100.00%

sangria-tcp-msgpack-example's Introduction

Sangria TCP/MessagePack Example

An example TCP GraphQL server that uses a binary data format (MessagePack).

After starting the server with

sbt run

If you would like to experiment and change code yourself, then better alternative would be an sbt-revolver plugin which is already available in the project. You just need yo run sbt ~reStart and it will automatically compile and restart the server on every change.

Motivation & Protocol

GraphQL claims to be transport and data format agnostic. At least this is what everybody says (including myself). It's time to prove this theory and implement something different from boring HTTP and JSON :)

This example uses binary protocol MessagePack and exposes GraphQL query engine via raw TCP connection. Some important points about the protocol and data the format:

  • In find it important for a GraphQL library not to depend on particular data format internally. This means that even during the execution of a query, an engine should construct target data format where possible. This avoids any unnecessary intermediate representation (like JSON) which just pollutes memory and increases GC time. This was one of the key design goals for sangria. In order to achieve this sangria has 2 main low-level abstractions: ResultMarshaller and InputUnmarshaller. They both provide the knowledge about the target data format. By adding following import:

    import sangria.marshalling.msgpack._

    You are bringing in the knowledge about the MessagePack data format (it imports appropriate ResultMarshaller and InputUnmarshaller instances). This allows execution engine directly construct binary data along the way, without any intermediate representation.

  • The binary protocol is pretty simple: client and servers send each other MessagePack Map values prefixed by 4 byte integer value in little-endian format. The prefix holds a size of the data frame (query/response) that follows it. Client always initiates the interaction.

Feedback

Feedback is very welcome in any form :) Feel free to make PRs, post issues or join the chat.

sangria-tcp-msgpack-example's People

Contributors

olegilyenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.