Installation of GraphQL

GraphQL Installation

As, we have a basic understanding of what GraphQL is, why we use GraphQL and how much GraphQL is useful in modern world technologies. So now, if we want to code with GraphQL, we should have GraphQL installed in our system.

Note: Before proceeding into the world of GraphQL, we must have a basic understanding of Node.js and a little knowledge of using command prompt.

Installing the GraphQL in our System

As we have read earlier that GraphQL is a specification, not an implementation. It is not specified or limited to a specific type of server. You can use it with different kinds of servers for which you are compatible with such as JavaScript, Python, C# etc.

For the installation of GraphQL, below are some basic requirements which our system must have: -

  1. The system must be running with an OS (Operating System)

There must be an Operating System in the system, which can be Windows, Linux or Mac OS. It is the foremost essential requirement for installing GraphQL in our system.

  • Node.js must be installed in the system.

We must check that if the latest version of Node.js is installed or not. If Node.js is not installed in the system, we can go to nodejs.org, and download the installer for the latest version of Node.js. Installing Node.js is an effortless task. You have to click 'Next' and 'I Agree,' and it will be installed in your system.

Now, we can proceed with the installation of GraphQL. We can easily set up GraphQL in our system with the following two methods: -

  1. We can directly execute the GraphQL query with the command-line tool.
  2. Or, we can set up and run the express app server to execute the GraphQL query.

Let us see how GraphQL can be installed with both methods one by one.

  1. Using Command-Line

Follow the below steps strictly to install GraphQL in your system using Commad-line -

  • Open the command prompt. It will look something like this: -
Installation of GraphQL
  • Now, write the following command:
npm init

press 'Enter,' you will see the following results

Installation of GraphQL
  • Press 'Enter' once again, and you will see the following window as a result.
Installation of GraphQL
  • press 'Enter', and enter the following command for installing GraphQL in your system:
‘npm install graphql --save’
  • After entering the above command, you will see the following result window, but it may take a while, so please wait for it,
GraphQL Installation
  • Now GraphQL is installed in the system, and you can start writing code with it.

Remember, in the above installation, we are not using any language features, but we will use other features like classes, fat arrow function, promises, etc., and all the mentioned features are ES6 features.

  • Set up and run the express app server to execute the GraphQL query.

For using this method, to install the GraphQL, we have to set up the express app first in our system. We have to adhere to the following instructions for setting up express in our system: -

  • First, write the following command, and press enter key:
‘npm install express --save’

You will see the following result window as a command prompt in installing express. Sometimes, it may take time, so please wait for a while.

GraphQL Installation

Now express is installed in your system, but you are required to install some other packages.

  • First, run the following command.
‘npm install -g express
GraphQL Installation
  • Now, run the following command to install the body-parser package,
npm install body-parser --save
GraphQL Installation

Now, run the following command to install the cookie-parser package in your system,

‘npm install cookie-parser --save
GraphQL Installation
  • Run the following command to install the multer package.
‘npm install multer --save
GraphQL Installation
  • All the required packages for the express app are installed in our system. And, the express app server is ready to execute the GraphQL query. So, now we have to write the following command in our command prompt window to install the GraphQL in our system using the express app:
‘npm install express express-graphql graphql --save

And press the enter key. You will see the following result window:

GraphQL Installation

The GraphQL is installed successfully in our system. Sometimes, it takes time, so you may have to wait for a while.

In the next section, we will learn how to write a GraphQL query and execute it.