Current trends in software and backend architecture have been evolving towards a more loosely coupled, more granular design. Most of you have heard of micro-service based architectures; the latest development in the past couple of years has been the advent of Serverless which allows you to run applications in very cost effective ephemeral services.
This is why it is important to have a proper gateway for your API that is able to route all your requests to the designated endpoint. GraphQL stands out in that respect as being a mature open sourced standard started at Facebook. Simona will demonstrate how to set up a GraphQL server locally, then explore the Query language and schema definitions it provides which allows you essentially query your mesh of services from a single point of entry.
The beauty is that it will notify you early if any of your endpoints is misbehaving or the schemas are out of date by erring out. Another advantage is that it allows for your API documentation to be a real time process and it will give you what one may call an API playground where you can query and explore your API. After exploring Serverless API, Simona will have a look at the more advanced features and standards around mutators and resolvers and then she will close by going all in, full Serverless and deploy a GraphQL server to a function in the cloud.
Turns out they do have a couple of things in common, they’re both on the hype train. Both GraphQL and Serverless are probably at the peak of their popularity where there’s literally a new community library probably created at this very moment.
Another thing that they have in common is that they’re both extremely appealing to js developers. That’s not to say that they’re not being used by other types of developer, but in particular js developers ted to be excited about graphql because it changes the balance and empowers frontend developers to define their data needs without having to rely on the backend team. At the same time, serverless is also of great help to front end developers because it enables us to create small, reusable APIs for our static websites.
Funnily enough, they both Both emerging at around the same time. Graphql was open sources as a specification in early 2015 and serverless late 2014.
But there still one thing that connects them very strongly and this is what we’re going to spend time on discovering today
You are probably familiar with the n+1 problem:when a request to load one item turns into n+1 requests since the item has n associated items. The term has been mainly described in the context of databases, specifically ORM where we lazy load child records, but it is in fact not confined to that. This is also known as a Chatty API which is one of the UGLY aspects of REST APIs. A chatty API, is any API that requires consumer to do more than a single call to perform a single, common operation
Why do we care about overfetching & under fetching so much? Well because they introduce a delay in our application. And our users perceive this delay in different ways depending on its length. Anything taking more than a second will prolly make our user context switch and more than 10 seconds abandon the task.
And many roundtrips to the server add delay to our application, same as parsing data to filter out fields.
Front end and backend teams sit together and define a contract that they’re going to communicate through; an interface between the two teams
A strongly typed definition of all the operations that can be run against the API and their types
A graphical interactive in-browser GraphQL IDE.
Syntax highlighting Intelligent type ahead of fields, arguments, types, and more. Real-time error highlighting and reporting. Automatic query completion. Run and inspect query results.
You only get the data you asked for. No more, no less. Single round trip. You can query as part of a mutation too! Clients determine the size and shape of data, not servers.
Codeless Because these services are created and managed by a third party, the services require you for the most part to write no back end code meaning your application has less code.
Less code leads to less bugs and your application becomes that much more easy to maintain.
When a new developer comes onto your team or you hand off your project to someone else in your organization, on-boarding becomes easier because the mental overhead is also decreased (there is simply less to understand). https://medium.com/@dabit3/full-stack-development-in-the-era-of-serverless-computing-c1e49bba8580?hss_channel=tw-740920470
To create a GraphQL backend for our API we use the graphql-js module that exports a core subset of GraphQL functionality for creation of type systems and servers.
Our entry point is the graphql function which is capable of parsing, validating and executing a graphql request. It requires a schema and a request string but we can also send query variables and operation names as well as context object
Queries side by side
Build Scalable APIs Using GraphQL and Serverless
Build Scalable APIs
using GraphQL and
Delay User Perception
0-100 ms Instant
100-300 ms Small perceptible delay
300-1000 ms Machine is working
1000+ ms Likely context switch
10000+ ms Task is abandoned
High performance Browser Networking
The fastest network request is a
request not made