Skip to content

Commit 612de87

Browse files
Graphql + React with Integration
1 parent cf0e780 commit 612de87

31 files changed

+15919
-2
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": ["@babel/preset-react", "@babel/preset-env",
3+
["@emotion/babel-preset-css-prop",{
4+
"sourceMap":false
5+
}]],
6+
"plugins": ["@babel/plugin-proposal-class-properties"]
7+
}

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.vscode/settings.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"activityBar.activeBackground": "#4476a1",
4+
"activityBar.activeBorder": "#d9a5c1",
5+
"activityBar.background": "#4476a1",
6+
"activityBar.foreground": "#e7e7e7",
7+
"activityBar.inactiveForeground": "#e7e7e799",
8+
"activityBarBadge.background": "#d9a5c1",
9+
"activityBarBadge.foreground": "#15202b",
10+
"editorGroup.border": "#4476a1",
11+
"panel.border": "#4476a1",
12+
"sideBar.border": "#4476a1",
13+
"statusBar.background": "#355c7d",
14+
"statusBar.border": "#355c7d",
15+
"statusBar.foreground": "#e7e7e7",
16+
"statusBarItem.hoverBackground": "#4476a1",
17+
"tab.activeBorder": "#4476a1",
18+
"titleBar.activeBackground": "#355c7d",
19+
"titleBar.activeForeground": "#e7e7e7",
20+
"titleBar.border": "#355c7d",
21+
"titleBar.inactiveBackground": "#355c7d99",
22+
"titleBar.inactiveForeground": "#e7e7e799"
23+
}
24+
}

README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
1-
# graphql-react-todo
2-
React+Graphql+lowdb
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm run server`
8+
9+
Runs the GraphQL server for the API.<br/>
10+
Open[http://localhost:3001](http:localhost:3001) to view the Graphql Playground.
11+
12+
If you add Any Mutation or Schema you have to reload the Page.<br/>
13+
14+
15+
### `npm start`
16+
17+
Runs the app in the development mode.<br />
18+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
19+
20+
The page will reload if you make edits.<br />
21+
You will also see any lint errors in the console.
22+
23+
### `npm test`
24+
25+
Launches the test runner in the interactive watch mode.<br />
26+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
27+
28+
### `npm run build`
29+
30+
Builds the app for production to the `build` folder.<br />
31+
It correctly bundles React in production mode and optimizes the build for the best performance.
32+
33+
The build is minified and the filenames include the hashes.<br />
34+
Your app is ready to be deployed!
35+
36+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
37+
38+
### `npm run eject`
39+
40+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
41+
42+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
43+
44+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
45+
46+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it..
47+
48+
### Code Splitting
49+
50+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
51+
52+
### `npm run build` fails to minify
53+
54+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

api/db/db.json

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"todos": [
3+
{
4+
"id": 1,
5+
"taskName": "Create a GraphQL Application",
6+
"status": "COMPLETED",
7+
"createdAt": "now"
8+
},
9+
{
10+
"id": "Uo1Q_luVS0VDL6gw0PiS6",
11+
"createdAt": 1589048279978,
12+
"taskName": "Graphql API",
13+
"status": "COMPLETED"
14+
},
15+
{
16+
"id": "K5IckZhwH89IfPFuFgTA8",
17+
"createdAt": 1589052270654,
18+
"taskName": "Create React App",
19+
"status": "COMPLETED"
20+
},
21+
{
22+
"id": "RdtI11gFCSCRlO-oxk2mW",
23+
"createdAt": 1589052308648,
24+
"taskName": "Create React App",
25+
"status": "COMPLETED"
26+
},
27+
{
28+
"id": "G-Wknu3Izhsoa7e9SPiA0",
29+
"createdAt": 1589052357975,
30+
"taskName": "Create React App",
31+
"status": "COMPLETED"
32+
},
33+
{
34+
"id": "UszJvY0CBESSkh0_WfFsn",
35+
"createdAt": 1589127186284,
36+
"taskName": "Create React App2",
37+
"status": "COMPLETED"
38+
},
39+
{
40+
"id": "7isBy9TlXXs9OChvekNhk",
41+
"createdAt": 1589128307575,
42+
"taskName": "creating ToDO Application",
43+
"status": "IN_PROGRESS"
44+
},
45+
{
46+
"id": "XSC2yVq-gDtnPy4cVWe03",
47+
"createdAt": 1589129962038,
48+
"taskName": "abhishek",
49+
"status": "NOT_STARTED"
50+
},
51+
{
52+
"id": "CBpdcwhU-auHtGD-wJ31x",
53+
"createdAt": 1589130034072,
54+
"taskName": "Testing this things for test",
55+
"status": "COMPLETED"
56+
},
57+
{
58+
"id": "MaKBt2D14DNukZzNduymO",
59+
"createdAt": 1589131214547,
60+
"taskName": "testing final data",
61+
"status": "COMPLETED"
62+
},
63+
{
64+
"id": "cq9MgU3Zr4KlXOJS_4-0f",
65+
"createdAt": 1589131260383,
66+
"taskName": "testing final data",
67+
"status": "NOT_STARTED"
68+
},
69+
{
70+
"id": "Rae4mmUa0mE90Mj-iDbiu",
71+
"createdAt": 1589131336732,
72+
"taskName": "final data testing",
73+
"status": "NOT_STARTED"
74+
},
75+
{
76+
"id": "RY0zgu0eQQGmwCoJUTmRt",
77+
"createdAt": 1589131424816,
78+
"taskName": "Testing this things for test again",
79+
"status": "NOT_STARTED"
80+
},
81+
{
82+
"id": "C9arOQnpe0lYTJPAdeOM-",
83+
"createdAt": 1589132894795,
84+
"taskName": "Create Todo Application for Server",
85+
"status": "NOT_STARTED"
86+
},
87+
{
88+
"id": "4jNp-RottlmfrkcmGR3ug",
89+
"createdAt": 1589132917860,
90+
"taskName": "Create Todo Application for Server",
91+
"status": "NOT_STARTED"
92+
}
93+
]
94+
}

api/db/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const low = require('lowdb');
2+
const FileSync = require('lowdb/adapters/FileSync');
3+
4+
const adapter = new FileSync('api/db/db.json');
5+
const db = low(adapter);
6+
const todosAction= require('./todo')
7+
8+
module.exports = {
9+
model:{
10+
TODOS:todosAction(db)
11+
},
12+
db
13+
}

api/db/todo.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
TODo Structure will be like
3+
{
4+
id:Number,
5+
taskName:String,
6+
status:COMPLETED|IN_PROGRESS| NOT_STARTED
7+
createdAt:Number
8+
}
9+
*/
10+
const { nanoid} = require('nanoid')
11+
const todosAction = db => {
12+
return {
13+
findByStatus(filter){
14+
return db.get('todos').filter({status:filter}).value();
15+
},
16+
17+
findAll(){
18+
return db.get('todos').value();
19+
},
20+
21+
addToDo(todo) {
22+
const newTodo = {id:nanoid(), createdAt:Date.now(), ...todo};
23+
db.get('todos').push(newTodo).write()
24+
return newTodo;
25+
},
26+
27+
updateToDo(todo) {
28+
if(todo.status ==='COMPLETED') {
29+
todo.status = 'NOT_STARTED'
30+
} else {
31+
todo.status ='COMPLETED'
32+
}
33+
let currentToDo = db.get('todos').find({id:todo.id}).set('status',todo.status).write();
34+
return currentToDo;
35+
}
36+
}
37+
};
38+
39+
module.exports = todosAction

api/resolvers.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const resolvers = {
2+
Query:{
3+
getAllToDo(initialValue, {input},context) {
4+
return context.model.TODOS.findAll()
5+
},
6+
7+
getToDoByStatus(initialValue, {status}, context){
8+
return context.model.TODOS.findByStatus(status);
9+
}
10+
},
11+
Mutation:{
12+
createToDo(initialValue, {input}, context){
13+
return context.model.TODOS.addToDo(input)
14+
},
15+
16+
updateToDo(initialValue, {input}, context) {
17+
console.log(input)
18+
return context.model.TODOS.updateToDo(input);
19+
}
20+
}
21+
};
22+
23+
module.exports = resolvers;

api/schemas.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const gql = require('graphql-tag');
2+
3+
const typeDefs = gql`
4+
5+
enum TODO_STATUS {
6+
IN_PROGRESS
7+
COMPLETED
8+
NOT_STARTED
9+
}
10+
11+
type ToDo {
12+
id:ID!
13+
taskName:String!
14+
status:TODO_STATUS!
15+
createdAt:String!
16+
}
17+
18+
input CreateToDo {
19+
taskName:String!
20+
status:TODO_STATUS!
21+
}
22+
23+
input UpdateToDo {
24+
id:ID!
25+
status:TODO_STATUS
26+
}
27+
28+
type Query {
29+
getAllToDo:[ToDo]!
30+
getToDoByStatus(status:TODO_STATUS):[ToDo]
31+
}
32+
33+
type Mutation {
34+
createToDo(input:CreateToDo):ToDo
35+
updateToDo(input:UpdateToDo):ToDo!
36+
}
37+
38+
`
39+
40+
module.exports = typeDefs;

api/server.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const {ApolloServer} = require('apollo-server');
2+
const resolvers = require('./resolvers');
3+
const typeDefs = require('./schemas');
4+
const {model,db} = require('./db')
5+
6+
7+
const server = new ApolloServer({
8+
typeDefs,
9+
resolvers,
10+
context(){
11+
return { model, db}
12+
}
13+
});
14+
15+
16+
server.listen(3001).then(_ => console.log('server is running at 3001'));

0 commit comments

Comments
 (0)