Learn to deploy a GraphQL Backend, design a schema, and implement a React UI. This 2-hour course walks you through it.
This app will use Dgraph Cloudâs built-in authorization to allow public posts
that anyone can see (even without logging in) but restrict posting messages to
users who are logged-in. Weâll also make some categories private, hiding them
from any users who havenât been granted viewer permissions. Users who are
logged-in can create new posts, and each post can have a stream of comments from
other users. A post is rendered on its own page, as follows:
This app will be completely serverless app:
users, posts and comments, and the links between them. Youâll naturally
want to explore that data graph as you work with the app, so GraphQL makes a
great choice. Also, in rendering the UI, GraphQL removes some complexity for
you.
If you built this app with REST APIs, for example, our clients (i.e., Web and
mobile) will have to programmatically manage getting all the data to render a
page. So, to render a post using a REST API, you will probably need to access
the /post/{id} endpoint to get the post itself, then the
/comment?postid={id} endpoint to get the comments, and then (iteratively for
each comment) access the /author/{id} endpoint. You would have to collect the
data from those endpoints, discard extra data, and then build a data structure
to render the UI. This approach requires different code in each version of the
app, and increases the engineering effort required and the opportunity for bugs
to occur in our app.
With GraphQL, rendering a page is much simpler. You can run a single GraphQL
query that gets all of the data for a post (its comments and the authors of
those comments) and then simply lay out the page from the returned JSON. GraphQL
gives you a query language to explore the appâs data graph, instead of having to
write code to build the data structure that you need from a series of REST API
calls.