Skip to content

Commit

Permalink
refactor(example): use latest graffiti
Browse files Browse the repository at this point in the history
  • Loading branch information
tothandras committed Nov 3, 2015
1 parent 736fed4 commit 6917d92
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 133 deletions.
54 changes: 28 additions & 26 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import koa from 'koa';
import serve from 'koa-static';
import mongoose from 'mongoose';
import graffiti from '@risingstack/graffiti';
import graffitiMongoose from '../src';
import {getSchema} from '../src';

import User from './user';

Expand All @@ -11,38 +10,41 @@ 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++) {
users.push(new User({
name: `User${i}`,
age: i,
createdAt: new Date() + i * 100,
friends: users.map((i) => i._id),
nums: [0, i],
bools: [true, false],
strings: ['foo', 'bar'],
removed: false,
body: {
eye: 'blue',
hair: 'yellow'
}
}));
}

User.create(users);
User.remove().then(() => {
const users = [];
for (let i = 0; i < 100; i++) {
users.push(new User({
name: `User${i}`,
age: i,
createdAt: new Date() + i * 100,
friends: users.map((i) => i._id),
nums: [0, i],
bools: [true, false],
strings: ['foo', 'bar'],
removed: false,
body: {
eye: 'blue',
hair: 'yellow'
}
}));
}
User.create(users);
});

const schema = getSchema([User]);

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

// attach graffiti-mongoose middleware
app.use(graffiti.koa({
prefix: '/graphql',
adapter: graffitiMongoose,
models: [User]
schema
}));

app.use(serve(__dirname + '/dist'));
// redirect all requests to /graphql
app.use(function *redirect() {
this.redirect('/graphql');
});

app.listen(port);

Expand Down
7 changes: 0 additions & 7 deletions example/build.sh

This file was deleted.

92 changes: 0 additions & 92 deletions example/index.html

This file was deleted.

11 changes: 3 additions & 8 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
"name": "graffiti-mongoose-example",
"description": "An example using graffiti-mongoose",
"scripts": {
"start": "node index.js",
"prestart": "npm run build",
"build": ". build.sh"
"start": "node index.js"
},
"dependencies": {
"@risingstack/graffiti": "^1.0.2",
"@risingstack/graffiti": "^2.0.0",
"@risingstack/graffiti-mongoose": "../",
"babel-runtime": "^5.8.20",
"graphiql": "^0.3.1",
"koa": "^1.1.0",
"koa-static": "^1.5.1",
"react": "0.14.0"
"koa": "^1.1.0"
},
"devDependencies": {
"babel": "^5.8.21"
Expand Down

0 comments on commit 6917d92

Please sign in to comment.