Current trends in software and backend architecture have been evolving towards a more loosely coupled more granular design. I am sure most of you have heard of microservice based architectures.
The latest development on that front 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.
18. @simona_cotin
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
32. @simona_cotin
–-Steve Jobs
The line of code that’s the
fastest to write, that never breaks,
that doesn’t need maintenance,
is the line you never had to write.
56. @simona_cotin
Easy Integration of Datasources
Autoscalability
Less code
Easy Abstraction of Datasources
Single Endpoint
Smaller no requests
Serverless GraphQL
57. @simona_cotin
Easy Integration of Datasources
Easy Abstraction of Datasources
Autoscalability
Single Endpoint
Less code
Smaller no requests
Dev productivity
The plot is this: Agnes here is looking at two pieces of tech apparently unrelated
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 graphql 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. As we’ve seen in Monica’s presentation, serverless can help us with a couple of things that browser don’t do. Things like storing secrets or
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. We can see this phenomenon elsewhere including web apis where we’re composing data from multiple endpoints or resources. 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.
https://hpbn.co/
A single request
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 single request
A single request
A single request
A single request
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.
But the true power of serverless doesn’t come only from the custom code, it comes from how easy we can integrate with multiple datasources and 3rd party apis.
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