Apollo Server와 Express를 이용한 GraphQL 구현
2022. 3. 7. 02:57ㆍ서버 프로그래밍
1. 가장 도움이 되는 예제
https://jason9319.tistory.com/411
2. async, await를 이용한 start 함수 작성 및 실행
async function startApolloServer(typeDefs, resolvers){
const server = new ApolloServer({typeDefs, resolvers})
const app = express();
await server.start();
server.applyMiddleware({app, path: '/graphql'});
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}${server.graphqlPath}`);
})
}
startApolloServer(typeDefs, resolvers);
3. Playground 변경 (Apollo Studio는 HTTPS만 동작 가능하기 때문)
function server() {
const serverApollo = new ApolloServer({
typeDefs: typeDefs,
resolvers: resolvers,
plugins: [ApolloServerPluginLandingPageGraphQLPlayground()] // this is the most important thing
})
serverApollo.listen().then(({ url }) => {
console.log(`Playground on: ${url}`)
})
}
https://github.com/apollographql/apollo-server/issues/5341
<기타 참고 자료>
https://www.apollographql.com/docs/apollo-server/integrations/middleware/#apollo-server-express
https://koonsland.tistory.com/148
https://www.daleseo.com/graphql-apollo-server/