Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
Lessons:14Length:1.1 hours

Next lesson playing in 5 seconds


Free Preview: Build APIs With GraphQL


  • Overview
  • Transcript

RESTful APIs are great: they follow a resource-oriented approach that is clear and well structured. But when the data gets more and more complex, the routes get longer and longer, and sometimes it isn’t even possible to fetch the data you want with only one request. This is where GraphQL comes into play. It’s designed to work with data represented by a graph, and it has a powerful query syntax for traversing, retrieving, and mutating data.

In this course, Markus Mühlberger will show you how to build a back-end GraphQL API. You'll start by using an interactive demo server to explore the basics of GraphQL and the syntax. Then you'll move on to implementing your own GraphQL server—a database of information about Star Wars characters—complete with queries, custom types, mutations, and a number of other advanced GraphQL features.

Learn JavaScript: The Complete Guide

We've built a complete guide to help you learn JavaScript, whether you're just getting started as a web developer or you want to explore more advanced topics.

1. Introduction

1.1 Introduction

RESTful APIs are great, they follow a resource oriented approach that is well structured and clear. But when the data gets more complex, the routes get longer and longer, and sometimes it isn't even possible to fetch the data you want with only one request. Nowadays, our data has more and more resemblance to a graph structure, and this is the point where GraphQL comes into play. It is designed to work with data represented by a graph and simply traverse it. Hello, and welcome to this Envato Tuts+ course. My name is Markus Muhlberger, and this is Build APIs With GraphQL. This course is a complete introduction to the GraphQL technology. I'm first going to give you a short introduction to the reasoning behind GraphQL, as well as the schema and queries. I'm also going to dedicate a complete section on querying with GraphQL where we also have a look at modifying data with mutations. The API we were using for the queries is built in another section where we have a look at types, root queries, interfaces, and lists using the JavaScript reference implementation and Express js. GraphQL is the future, originally designed by engineers at Facebook, companies all over the world are using it now. Let's get you hooked on GraphQL, I will see you in the first lesson.

1.2 Installing the Prerequisites

Hi, and welcome back to build APIs with GraphQL. In this lesson, we will install all prerequisites needed for this course and set up the Node.js server to run the GraphQL API. First of all, we need Node.js. Depending on your operating system, you can either install it from the official website, use a version manager like nbm, or, if you're on a Mac, like I am, use Homebrew. The second thing you will need is a package manager. npm, Node's default, is fine, but I like Yarn, and we'll use that. Finally, I'm going to install nodemon, so the server automatically restarts when a file is changed. Without it, you would have to kill and restart the Node process every time you save a change to the file. To install it, either run yarn global add nodemon or npm install -g nodemon. Now that all prerequisites are installed, we can start building the server. I'm going to use the Express JS web framework, because the reference implementation of GraphQL has an Express-compatible package that is very easy to add. Let's get started by running yarn add express express-graphql to initialize the package to the JSON file and install the two necessary packages. Then, in your editor of choice, -atom, add a server.js file under projects folder. This is where our Express app is going to live. We're using plain Node here, so we need to use the require syntax and not import. First, let's require express. Then, we also need expressGraphql. I'm going to store it in the expressGraphQL variable. Now I can create an express app by calling the required express module. Express GraphQL is a middleware for Express, so we can call app.use and pass the GraphQL endpoint. Enter required package. You can also pass some configuration options to Express GraphQL, like graphical, which we will use as a client. Finally, we have to start the server by calling app.listen and pass in a port. In the callback, let's also confirm that the server is running with a consulted lock statement and output URL. In this shell, we can now call node1 server, which will start the server. A neat treat on Mac OS, when you double-click the URL while holding down the command key, it will automatically open the page in your default browser. In our next lesson, we are going to talk about the advantages of GraphQL compared to our classic RESTful API. See you there.