forked from apollographql/odyssey-lift-off-part5-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to async function for server start instead of callback
- Loading branch information
Showing
1 changed file
with
18 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |