Skip to content

Commit d526d77

Browse files
Merge pull request #2 from anthonypena97/develop
Feature/2/Connected schema to mongodb and deployed to heroku + more queries and mutations
2 parents 18ccfc7 + d4f42d2 commit d526d77

File tree

11 files changed

+525
-49
lines changed

11 files changed

+525
-49
lines changed

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npm start

package-lock.json

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

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "flutter-graphql",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "server/app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"install": "cd server && npm i",
9+
"start": "cd server && node app.js"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/anthonypena97/flutter-graphql.git"
14+
},
15+
"author": "",
16+
"license": "ISC",
17+
"bugs": {
18+
"url": "https://github.com/anthonypena97/flutter-graphql/issues"
19+
},
20+
"homepage": "https://github.com/anthonypena97/flutter-graphql#readme"
21+
}

server/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
.DS_Store
2+
.DS_Store
3+
.env

server/app.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1+
require('dotenv').config()
2+
3+
const cors = require('cors');
4+
15
const express = require('express');
26
const {graphqlHTTP} = require('express-graphql');
37

48
const schema = require('./schema/schema');
59

10+
const mongoose = require('mongoose');
11+
612
const app = express();
713

814
// Middleware
15+
app.use(cors());
916
app.use('/graphql', graphqlHTTP({
1017
schema: schema,
1118
graphiql: true,
1219
pretty: true,
1320
}));
1421

15-
const PORT = 4000;
16-
17-
app.listen(PORT, ()=>{
18-
console.log(`Listening for requests on port ${PORT}`);
19-
});
22+
const PORT = process.env.PORT || 4000;
23+
24+
mongoose.connect(`mongodb+srv://${process.env.MONGO_USERNAME}:${process.env.MONGO_PASSWORD}@graphqlcluster.6k90h.mongodb.net/${process.env.MONGO_DATABASE}?retryWrites=true&w=majority`, {useNewUrlParser: true, useUnifiedTopology: true})
25+
.then(() =>{
26+
app.listen(PORT, ()=>{
27+
console.log(`Listening for requests on port ${PORT}`);
28+
});
29+
30+
})
31+
.catch((e)=>{console.log(`Error ::: ${e}`)})

server/models/hobby.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const mongoose = require('mongoose');
2+
const MSchema = mongoose.Schema
3+
4+
const hobbySchema = new MSchema({
5+
title: String,
6+
description: String,
7+
userId: String
8+
});
9+
10+
module.exports = mongoose.model('Hobby', hobbySchema);

server/models/post.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const mongoose = require('mongoose');
2+
const MSchema = mongoose.Schema;
3+
4+
const postSchema = new MSchema({
5+
comment: String,
6+
userId: String
7+
});
8+
9+
module.exports = mongoose.model('Post', postSchema);

server/models/user.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const mongoose = require('mongoose');
2+
const MSchema = mongoose.Schema
3+
4+
const userSchema = new MSchema({
5+
name: String,
6+
age: Number,
7+
profession: String,
8+
});
9+
10+
module.exports = mongoose.model('User', userSchema);

0 commit comments

Comments
 (0)