Skip to content

Commit

Permalink
refactor(example): optimise seed data persist
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton committed Oct 18, 2015
1 parent e426611 commit 4b71175
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ const port = process.env.PORT || 8080;

mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/graphql');

// Generate sample data
User.remove();
const users = [];
for (let i = 0; i < 100; i++) {
const user = new User({
users.push(new User({
name: `User${i}`,
age: i,
createdAt: new Date() + i * 100,
Expand All @@ -26,11 +27,12 @@ for (let i = 0; i < 100; i++) {
eye: 'blue',
hair: 'yellow'
}
});
users.push(user);
user.save();
}));
}

User.create(users);

// Set up example server
const app = koa();

// attach graffiti-mongoose middleware
Expand All @@ -43,4 +45,5 @@ app.use(graffiti.koa({
app.use(serve(__dirname + '/dist'));

app.listen(port);

console.log(`Started on http://localhost:${port}/`);

0 comments on commit 4b71175

Please sign in to comment.