728x90
https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-express
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`;
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};
const server = new ApolloServer({ typeDefs, resolvers });
const app = express();
server.applyMiddleware({ app });
app.listen({ port: 4000 }, () =>
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`)
);
나는 원래 'apllo-server'에서 ApolloServer를 import 했었는데,
server.express.use를 써보려 하니까 안돼서
'apllo-server-express'에서 ApolloServer를 import하고, app.use를 쓰니까 됐다!
'Development > GraphQL' 카테고리의 다른 글
GQL서버 init (0) | 2020.04.10 |
---|---|
[GraphQL] passport로 인증기능 만들기 (2) | 2020.03.23 |
[GraphQL / Apollo] 도입해보기 (0) | 2020.03.02 |
[GraphQL / Apollo] 오프라인 노트앱 만들기 (0) | 2020.02.16 |