-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from NisanurBulut/dev-mernghera
Dev mernghera is complated
- Loading branch information
Showing
14 changed files
with
1,105 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# dependencies | ||
/*/node_modules | ||
/*/backend/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
MONGO_DB: 'heraDB', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const Birthday = require('../../models/Birthday'); | ||
|
||
module.exports = { | ||
Query: { | ||
getBirthdays: async () => { | ||
try { | ||
const birthdays = await Birthday.find(); | ||
return birthdays; | ||
} catch (err) { | ||
console.log(err); | ||
throw new Error(err); | ||
} | ||
}, | ||
}, | ||
Mutation: { | ||
async createBirthday(parent, args) { | ||
try { | ||
const newBirthday = new Birthday({ | ||
name: args.name, | ||
age: args.age, | ||
imageUrl: args.imageUrl, | ||
}); | ||
const response = await newBirthday.save(); | ||
console.log(response._doc); | ||
return { | ||
...response._doc, | ||
_id: response._id.toString(), | ||
}; | ||
} catch (err) { | ||
throw new Error(err); | ||
} | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const gql = require('graphql-tag'); | ||
|
||
module.exports = gql` | ||
type Birthday { | ||
id: ID! | ||
name: String! | ||
age: Int! | ||
imageUrl: String! | ||
} | ||
type Query { | ||
getBirthdays: [Birthday] | ||
} | ||
type Mutation { | ||
createBirthday(name: String!, age: Int!, imageUrl: String!): Birthday! | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const express = require('express'); | ||
const mongoose = require('mongoose'); | ||
const schema = require('./graphql/typeDefs'); | ||
const bodyParser = require('body-parser'); | ||
const cors = require('cors'); | ||
const { ApolloServer } = require('apollo-server-express'); | ||
|
||
const typeDefs = require('./graphql/typeDefs'); | ||
const birthdayResolvers = require('./graphql/resolvers/birthday'); | ||
const { MONGO_DB } = require('./config.js'); | ||
|
||
|
||
const url = `mongodb://localhost:27017/${MONGO_DB}`; | ||
const connect = mongoose.connect(url, { useNewUrlParser: true }); | ||
connect.then((db) => { | ||
console.log('Connected correctly to server!'); | ||
}, (err) => { | ||
console.log(err); | ||
}); | ||
|
||
const server = new ApolloServer({ | ||
typeDefs: schema, | ||
resolvers: birthdayResolvers | ||
}); | ||
const app = express(); | ||
app.use(bodyParser.json()); | ||
app.use('*', cors()); | ||
server.applyMiddleware({ app }); | ||
app.listen({ port: 4000 }, () => | ||
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const BirthdaySchema = new Schema({ | ||
name: String, | ||
imageUrl: String, | ||
age: Number | ||
}); | ||
|
||
module.exports = mongoose.model('Birthday', BirthdaySchema); |
Oops, something went wrong.