Skip to content

Instantly share code, notes, and snippets.

@dalegaspi
Created June 7, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalegaspi/8b7e4fe8de9ffc77817f1ca57cb416d7 to your computer and use it in GitHub Desktop.
Save dalegaspi/8b7e4fe8de9ffc77817f1ca57cb416d7 to your computer and use it in GitHub Desktop.
Thoughts on GraphQL and Sangria

Thoughts on GraphQL and Sangria

I have recently implemented GraphQL as an enhancement to an existing REST microservice application (written in Akka HTTP Framework) and here are a few random thoughts:

  • Sangria certainly makes things easy to adapt GraphQL to most Scala projects. The way the resolvers are implemented are elegant and simple; e.g. there's no explicit way of different handling whether your resolve method is a Future[T] or just a value; it's treated the same in code.
  • Sangria can use existing case classes for the GraphQL objects, and provides macros to avoid boilerplate. However, there are a bunch of caveats and limitations; we are using scalaxb to generate our case classes from XSDs, and sadly these are not workable with the Sangria macros. Fortunately, with the awesome libray Chimney this makes it less painful
  • Testability is dialed-up to 11. There are a lot of GraphQL clients available, but the one that I used is graphql-playground. I embedded it as a resource and route it to GET /rest/v1/graphql and it just works with the POST /rest/v1/graphql out of the box.
  • GraphQL is cool, and extending the REST capability to have it is awesome. However, I don't necessarily agree that it's a replacement with the classic REST endpoints.
    There are two use cases that is addressed by GraphQL nicely: discoverability of available data, and clarity of what the client asks for. Building comprehensive UI frontends of existing services makes a good case to use GraphQL, but for high-throughput services where the call pattern and data contracts are pre-determined, GraphQL may be overkill and presents an overhead that's unnecessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment