Skip to content

Commit

Permalink
Merge pull request #13 from NisanurBulut/dev-mernghera
Browse files Browse the repository at this point in the history
Dev mernghera is complated
  • Loading branch information
NisanurBulut authored Mar 20, 2021
2 parents cc205c4 + c7756c1 commit 967a14a
Show file tree
Hide file tree
Showing 14 changed files with 1,105 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# dependencies
/*/node_modules
/*/backend/node_modules
/.pnp
.pnp.js

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
<hr>
1. <b> Hera </b> </br>
Hera is a birthday reminder application. Refers to the input level to ReactJs.
Hera is a birthday reminder application and Hera is a MERNG work.Uses MongoDb for database and GraphQL for backend api.Apollo-Server was used with this entry level study.

![App-Hera](https://github.com/NisanurBulut/MythologyOfReactJs/blob/master/Trailers/Trailer_Hera.gif)
<br>

### Installation
- npm install --save-dev nodemon
- npm install apollo-server graphql mongoose
- npm i graphql-tag
-
<hr>
2. <b> Arena </b> </br>
1. <b> Arena </b> </br>
Arena is the mix project Refers to the context Api

![App-Arena](https://github.com/NisanurBulut/MythologyOfReactJs/blob/master/Trailers/Trailer_Arena.gif)
Expand Down
Binary file modified Trailers/Trailer_Hera.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Trailers/Trailer_Hera_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions hera/backend/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
MONGO_DB: 'heraDB',
};
34 changes: 34 additions & 0 deletions hera/backend/graphql/resolvers/birthday.js
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);
}
},
},
};
16 changes: 16 additions & 0 deletions hera/backend/graphql/typeDefs.js
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!
}
`;
30 changes: 30 additions & 0 deletions hera/backend/index.js
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}`));
11 changes: 11 additions & 0 deletions hera/backend/models/Birthday.js
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);
Loading

0 comments on commit 967a14a

Please sign in to comment.