From d5a80afff154ed018382f6dbab1690ca30e34f20 Mon Sep 17 00:00:00 2001 From: Michelle Mabuyo Date: Mon, 16 Aug 2021 15:22:50 -0400 Subject: [PATCH] switch to async function for server start instead of callback --- src/index.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/index.js b/src/index.js index e806576f..8586d413 100644 --- a/src/index.js +++ b/src/index.js @@ -1,23 +1,25 @@ const { ApolloServer } = require('apollo-server'); const typeDefs = require('./schema'); const resolvers = require('./resolvers'); - const TrackAPI = require('./datasources/track-api'); -const server = new ApolloServer({ - typeDefs, - resolvers, - dataSources: () => { - return { - trackAPI: new TrackAPI(), - }; - }, -}); +async function startApolloServer(typeDefs, resolvers) { + const server = new ApolloServer({ + typeDefs, + resolvers, + dataSources: () => { + return { + trackAPI: new TrackAPI(), + }; + }, + }); -server.listen().then(() => { + const { url, port } = await server.listen(); console.log(` - 🚀 Server is running! - 🔉 Listening on port 4000 - 📭 Query at https://studio.apollographql.com/dev - `); -}); + 🚀 Server is running + 🔉 Listening on port ${port} + 📭 Query at ${url} + `); +} + +startApolloServer(typeDefs, resolvers);