Apollo Server is the most popular open source library that works with GraphQL (server and client). It has a lot of documentation and is really easy to implement.
The following diagram explains how Apollo Server works in the client and the server:
We are going to use Express to set up our Apollo Server and Sequelize ORM to handle our PostgreSQL database. So, initially, we need to do some imports. The required file can be found at /backend/src/index.ts:
// Dependencies
import { ApolloServer, makeExecutableSchema } from 'apollo-server'
// Models
import models from './models'
// Type Definitions & Resolvers
import resolvers from './graphql/resolvers'
import typeDefs from './graphql/types'
// Configuration
import { $server } from '../config'
First, we need to create our schema using makeExecutableSchema by passing typeDefs and resolvers:
// Schema
const schema = makeExecutableSchema({
typeDefs,
resolvers
})
Then, we need...