Skip to content

Commit 42caaa1

Browse files
update
1 parent e35e555 commit 42caaa1

25 files changed

+837
-93
lines changed

app.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import express from 'express';
2+
import bodyParser from 'body-parser';
3+
import graphqlHTTP from 'express-graphql';
4+
import Routes from './config/Routes';
5+
6+
//DB
7+
import ToDo from './model/todo';
8+
//Graph
9+
import schema from './graphql/Schema/Schema';
10+
import { graphql } from 'graphql';
11+
12+
const app = express();
13+
app.use(bodyParser.urlencoded({ extended: true }))
14+
15+
//SECTION Render static html
16+
app.get(Routes.base, (req, res) => {
17+
res.sendFile(__dirname + Routes.index)
18+
})
19+
//SECTION Play with graph schema
20+
app.use(Routes.Graph, graphqlHTTP(req => ({
21+
schema
22+
,graphiql:true
23+
})));
24+
25+
//SECTION The app
26+
app.post(Routes.quotes, (req, res) => {
27+
// Insert into TodoList Collection
28+
var todoItem = new ToDo({
29+
itemId: 1,
30+
item: req.body.item,
31+
completed: false
32+
});
33+
34+
todoItem.save((err, result) => {
35+
if (err) { console.log("---TodoItem save failed " + err) }
36+
console.log("TodoItem saved successfully " + todoItem.item)
37+
res.redirect(Routes.base)
38+
});
39+
})
40+
export default app ;

config/Routes.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"Graph":"/graphql",
3+
"base":"/",
4+
"quotes":"/quotes",
5+
"index":"index.html"
6+
}

config/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"DB": "mongodb://localhost:27017/Graphql",
3+
"PORT": 3000
4+
}

dist/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
package-lock.json/
3+
4+
/node_modules
5+
/package-lock.json
6+
node_modules
7+
package-lock.json

dist/graphql/Schema/Schema.js

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/graphql/Schema/Schema.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/model/todo.js

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/model/todo.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/package.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "graphql-express",
3+
"version": "1.0.0",
4+
"description": "Graphql Express-MongoDB server",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "nodemon index.js --exec babel-node --presets es2015,stage-2",
8+
"build": "gulp",
9+
"dev": "nodemon index.js"
10+
},
11+
"dependencies": {
12+
"body-parser": "^1.15.2",
13+
"express": "^4.14.0",
14+
"express-graphql": "^0.6.1",
15+
"graphql": "^0.8.2",
16+
"mongoose": "^4.7.2"
17+
},
18+
"devDependencies": {
19+
"babel": "^6.5.2",
20+
"babel-cli": "^6.18.0",
21+
"babel-core": "^6.26.0",
22+
"babel-plugin-add-module-exports": "0.2.1",
23+
"babel-plugin-transform-runtime": "^6.23.0",
24+
"babel-preset-es2015": "^6.18.0",
25+
"babel-preset-stage-0": "^6.16.0",
26+
"babel-preset-stage-2": "6.24.1",
27+
"del": "^3.0.0",
28+
"gulp": "3.9.1",
29+
"gulp-env": "^0.4.0",
30+
"gulp-babel": "^7.0.0",
31+
"gulp-eslint": "^4.0.0",
32+
"gulp-istanbul": "1.1.2",
33+
"gulp-load-plugins": "^1.5.0",
34+
"gulp-mocha": "^4.3.1",
35+
"gulp-newer": "^1.3.0",
36+
"gulp-nodemon": "^2.2.1",
37+
"gulp-plumber": "^1.1.0",
38+
"gulp-sourcemaps": "^2.6.1",
39+
"gulp-util": "^3.0.8",
40+
"isparta": "4.0.0",
41+
"mocha": "4.0.1",
42+
"run-sequence": "^2.2.0",
43+
"nodemon": "^1.11.0"
44+
},
45+
"babel": {
46+
"presets": [
47+
"es2015",
48+
"stage-2"
49+
],
50+
"plugins": [
51+
"add-module-exports"
52+
]
53+
}
54+
}

0 commit comments

Comments
 (0)