GraphQL - Server Side (Part 1)
By Adrian Barbic at
How to setup GraphQL server side using Apollo. Updated!!
Step 1:
First install Apollo Server and Graphql packages
npm install apollo-server graphql
In the server folder (if you have seperated server and client code into different folders) create a file called schema.js
Step 2:
Next we need to call the gql
template literal from apollo-server
const { gql } = require("apollo-server");
Step 3:
Now time to define our types
type Book {
id: ID!
title: String!
author: Author!
thumbnail: String
length: Int
modulesCount: Int
}
type Author {
id: ID!
name: String!
photo: String
}
You'll notice that we use an exclimation mark at the end of some of the fields. This is to indicate that the value cannot be null.