上QQ阅读APP看书,第一时间看更新
The basic setup
The basic setup to make an application work is the logical request flow, which looks as follows:
Here's how the logical request flow works:
- The client requests our site.
- The Express.js server handles these requests and serves a static HTML file.
- The client downloads all necessary files, according to this HTML file. The files also include a bundled JavaScript file.
- This bundled JavaScript file is our React application. After executing all JavaScript code from this file, all required Ajax alias GraphQL requests are made to our Apollo Server.
- Express.js receives the requests and passes them to our Apollo endpoint.
- Apollo queries all requested data from all available systems, such as our SQL server or third-party services, merges the data, and sends it back as JSON.
- React can render the JSON data to HTML.
This workflow is the basic setup to make an application work. In some cases, it makes sense to offer server-side rendering for our client. The server would need to render and send all XMLHttpRequests itself before returning the HTML to the client. The user will save one or more round trips if the server sends the requests on the initial load. We will focus on this topic in a later chapter, but that's the application architecture in a nutshell. With that in mind, let's get hands-on and set up our development environment.