-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.js
41 lines (36 loc) · 1 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import express from "express";
import { ApolloServer, gql } from "apollo-server-express";
import faker from "faker";
import times from "lodash.times";
import random from "lodash.random";
import typeDefs from "./schema";
import resolvers from "./resolvers";
import db from "./models";
const server = new ApolloServer({
typeDefs: gql(typeDefs),
resolvers,
context: { db }
});
const app = express();
server.applyMiddleware({ app });
app.use(express.static("app/public"));
db.sequelize.sync().then(() => {
// populate author table with dummy data
db.author.bulkCreate(
times(10, () => ({
firstName: faker.name.firstName(),
lastName: faker.name.lastName()
}))
);
// populate post table with dummy data
db.post.bulkCreate(
times(10, () => ({
title: faker.lorem.sentence(),
content: faker.lorem.paragraph(),
authorId: random(1, 10)
}))
);
app.listen({ port: 4000 }, () =>
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`)
);
});