Configuring GraphQL with the order-ms service

Let's take the order-ms service as an example and set up GraphQL there. First, we will need to install some dependencies:

$ npm install --save apollo-server-express graphql-tools graphql

Then, we need to create a new file called graphql.ts under src/graphql, with the following content:

import { ApolloServer, gql } from 'apollo-server-express'export class GraphQL {  public typeDefs: string  public resolvers: Object  public server: ApolloServer  constructor() {    this.typeDefs = gql`      type Query {        hello: String      }    `    this.resolvers = {      Query: {        hello: () => 'Hello world!',      },    }    this.server = new ApolloServer({      typeDefs: this.typeDefs,      resolvers: this.resolvers,    })  }  public setup(app): void { this.server.applyMiddleware({ ...

Get Hands-On RESTful Web Services with TypeScript 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.