Skip to content

Commit 54c77f1

Browse files
authentication added with LOWDB
1 parent aeff1c7 commit 54c77f1

File tree

8 files changed

+684
-62
lines changed

8 files changed

+684
-62
lines changed

.vscode/settings.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@
77
"activityBar.inactiveForeground": "#e7e7e799",
88
"activityBarBadge.background": "#d9a5c1",
99
"activityBarBadge.foreground": "#15202b",
10-
"editorGroup.border": "#4476a1",
11-
"panel.border": "#4476a1",
12-
"sideBar.border": "#4476a1",
1310
"statusBar.background": "#355c7d",
14-
"statusBar.border": "#355c7d",
1511
"statusBar.foreground": "#e7e7e7",
1612
"statusBarItem.hoverBackground": "#4476a1",
17-
"tab.activeBorder": "#4476a1",
1813
"titleBar.activeBackground": "#355c7d",
1914
"titleBar.activeForeground": "#e7e7e7",
20-
"titleBar.border": "#355c7d",
2115
"titleBar.inactiveBackground": "#355c7d99",
2216
"titleBar.inactiveForeground": "#e7e7e799"
23-
}
17+
},
18+
"peacock.color": "#355c7d"
2419
}

api/db/db.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@
3030
"taskName": "hello how are you",
3131
"status": "NOT_STARTED"
3232
}
33+
],
34+
"users": [
35+
{
36+
"username": "ABhishek",
37+
"password": "test"
38+
}
3339
]
3440
}

api/db/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
const low = require('lowdb');
2-
const FileSync = require('lowdb/adapters/FileSync');
1+
const low = require("lowdb");
2+
const FileSync = require("lowdb/adapters/FileSync");
33

4-
const adapter = new FileSync('api/db/db.json');
4+
const adapter = new FileSync("api/db/db.json");
55
const db = low(adapter);
6-
const todosAction= require('./todo')
6+
const todosAction = require("./todo");
7+
const authAction = require("./auth");
78

89
module.exports = {
9-
model:{
10-
TODOS:todosAction(db)
10+
model: {
11+
TODOS: todosAction(db),
12+
AUTH: authAction(db),
1113
},
12-
db
13-
}
14+
db,
15+
};

api/resolvers.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
const resolvers = {
2-
Query:{
3-
getAllToDo(initialValue, {input},context) {
4-
return context.model.TODOS.findAll()
2+
Query: {
3+
getAllToDo(initialValue, { input }, context) {
4+
return context.model.TODOS.findAll();
55
},
66

7-
getToDoByStatus(initialValue, {status}, context){
7+
getToDoByStatus(initialValue, { status }, context) {
88
return context.model.TODOS.findByStatus(status);
9-
}
9+
},
1010
},
11-
Mutation:{
12-
createToDo(initialValue, {input}, context){
13-
return context.model.TODOS.addToDo(input)
11+
Mutation: {
12+
createToDo(initialValue, { input }, context) {
13+
return context.model.TODOS.addToDo(input);
1414
},
1515

16-
updateToDo(initialValue, {input}, context) {
17-
console.log(input)
16+
updateToDo(initialValue, { input }, context) {
17+
console.log(input);
1818
return context.model.TODOS.updateToDo(input);
19-
}
20-
}
19+
},
20+
21+
createUser(initialValue, { input }, context) {
22+
console.log("input", input);
23+
return context.model.AUTH.addUser(input);
24+
},
25+
26+
findSavedUser(initialValue, { input }, context) {
27+
return context.model.AUTH.findSavedUser(input);
28+
},
29+
},
2130
};
2231

23-
module.exports = resolvers;
32+
module.exports = resolvers;

api/schemas.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
1-
const gql = require('graphql-tag');
1+
const gql = require("graphql-tag");
22

33
const typeDefs = gql`
4-
54
enum TODO_STATUS {
65
IN_PROGRESS
76
COMPLETED
87
NOT_STARTED
98
}
109
1110
type ToDo {
12-
id:ID!
13-
taskName:String!
14-
status:TODO_STATUS!
15-
createdAt:String!
11+
id: ID!
12+
taskName: String!
13+
status: TODO_STATUS!
14+
createdAt: String!
15+
}
16+
17+
type User {
18+
username: String!
19+
password: String!
1620
}
1721
1822
input CreateToDo {
19-
taskName:String!
20-
status:TODO_STATUS!
23+
taskName: String!
24+
status: TODO_STATUS!
25+
}
26+
27+
input CreateUser {
28+
username: String!
29+
password: String!
2130
}
2231
2332
input UpdateToDo {
24-
id:ID!
25-
status:TODO_STATUS
33+
id: ID!
34+
status: TODO_STATUS
2635
}
2736
2837
type Query {
29-
getAllToDo:[ToDo]!
30-
getToDoByStatus(status:TODO_STATUS):[ToDo]
38+
getAllToDo: [ToDo]!
39+
getToDoByStatus(status: TODO_STATUS): [ToDo]
3140
}
3241
3342
type Mutation {
34-
createToDo(input:CreateToDo):ToDo
35-
updateToDo(input:UpdateToDo):ToDo!
43+
createToDo(input: CreateToDo): ToDo
44+
updateToDo(input: UpdateToDo): ToDo!
45+
createUser(input: CreateUser): User
46+
findSavedUser(input: CreateUser): User
3647
}
48+
`;
3749

38-
`
39-
40-
module.exports = typeDefs;
50+
module.exports = typeDefs;

api/server.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
const {ApolloServer} = require('apollo-server');
2-
const resolvers = require('./resolvers');
3-
const typeDefs = require('./schemas');
4-
const {model,db} = require('./db')
5-
1+
const { ApolloServer } = require("apollo-server");
2+
const resolvers = require("./resolvers");
3+
const typeDefs = require("./schemas");
4+
const { model, db } = require("./db");
65

76
const server = new ApolloServer({
87
typeDefs,
98
resolvers,
10-
context(){
11-
return { model, db}
12-
}
9+
context(req) {
10+
return { model, db };
11+
},
1312
});
1413

15-
16-
server.listen(3001).then(_ => console.log('server is running at 3001'));
14+
server.listen(3001).then((_) => console.log("server is running at 3001"));

0 commit comments

Comments
 (0)