Scala is a very popular language nowadays and it’s often chosen to deliver efficient and scalable systems. It leverages the Java VM, known for its reliability and robustness. Support for Functional Programming, rich ecosystem and stable foundation allow building fast applications, quickly. In the next chapters you’ll learn how to build your own GraphQL server using Scala and the following technologies:
Scala – Scala language
I assume you’re familiar with GraphQL concepts, but if not, you can visit GraphQL site to learn more about that.
A GraphQL server should be able to:
Receive requests following the GraphQL format, for example:
{ "query": "query { allLinks { url } } " }
Connect to one or more data sources, like databases or other AP ls and format obtained information.
Response with the requested data, such as this one:
{
"data": { "allLinks": { "url": "http://graphql.org/" } }
}
Validate incoming requests accordingly to the schema definition and supported formats. For example, if a query is made with an unknown field, the response should be something like:
{
"errors" : [ {
"message": "Cannot query field \"unknown\" on type \"Link\"."
} ]
}
As you can see our server will be really simple, but real GraphQL implementation can do much more than this. (We will explore it more later on.)
Schema-first GraphQL development forces frontend and backend developers to agree on a strict contract up front, enabling them to work quickly and efficiently while staying on spec. It improves both your AP l’s performance and the performance of your team in general. Sensibly then, the experience of building a GraphQL server starts with working on its schema.
You’ll see in this chapter that the main steps you follow will be something like this:
A schema is a contract between the frontend and backend, so keeping it at the center allows both sides of the development to evolve without going off the spec. This also makes it easier to parallelize the work. Since the frontend can move on with complete knowledge of the API from the start, using a simple mocking service (or even a full backend such as Graphcool) which can later be easily replaced with the final server.