├── .gitignore ├── rq-todos ├── .gitignore ├── README.md ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt ├── src │ ├── App.css │ ├── App.test.tsx │ ├── App.tsx │ ├── index.css │ ├── index.tsx │ ├── lib │ │ └── api.ts │ ├── logo.svg │ ├── react-app-env.d.ts │ ├── reportWebVitals.ts │ └── setupTests.ts ├── tsconfig.json └── yarn.lock ├── rtk-todos ├── .gitignore ├── README.md ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt ├── src │ ├── App.css │ ├── App.test.tsx │ ├── App.tsx │ ├── index.css │ ├── index.tsx │ ├── logo.svg │ ├── react-app-env.d.ts │ ├── reportWebVitals.ts │ ├── setupTests.ts │ └── store.ts ├── tsconfig.json └── yarn.lock └── server ├── .eslintrc.js ├── .gitignore ├── .prettierrc ├── README.md ├── nest-cli.json ├── package.json ├── src ├── app.module.ts ├── main.ts └── modules │ └── todos │ ├── todo.controller.ts │ └── todo.module.ts ├── test ├── app.e2e-spec.ts └── jest-e2e.json ├── tsconfig.build.json ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /rq-todos/.gitignore: -------------------------------------------------------------------------------- 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* 24 | -------------------------------------------------------------------------------- /rq-todos/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /rq-todos/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rq-todos", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "@types/jest": "^26.0.15", 10 | "@types/node": "^12.0.0", 11 | "@types/react": "^17.0.0", 12 | "@types/react-dom": "^17.0.0", 13 | "axios": "^0.23.0", 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-query": "^3.26.0", 17 | "react-scripts": "4.0.3", 18 | "typescript": "^4.1.2", 19 | "web-vitals": "^1.0.1" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /rq-todos/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jherr/rtk-query-vs-rq/20763efa13f5d1318cecb102551a681d39216520/rq-todos/public/favicon.ico -------------------------------------------------------------------------------- /rq-todos/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /rq-todos/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jherr/rtk-query-vs-rq/20763efa13f5d1318cecb102551a681d39216520/rq-todos/public/logo192.png -------------------------------------------------------------------------------- /rq-todos/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jherr/rtk-query-vs-rq/20763efa13f5d1318cecb102551a681d39216520/rq-todos/public/logo512.png -------------------------------------------------------------------------------- /rq-todos/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /rq-todos/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /rq-todos/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /rq-todos/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /rq-todos/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { useRef } from "react"; 2 | import { 3 | useQuery, 4 | useMutation, 5 | QueryClientProvider, 6 | QueryClient, 7 | } from "react-query"; 8 | import { ReactQueryDevtools } from "react-query/devtools"; 9 | import axios from "axios"; 10 | 11 | import { getTodos, Todo, updateTodo, deleteTodo, createTodo } from "./lib/api"; 12 | 13 | export const axiosClient = axios.create({ 14 | baseURL: "http://localhost:4000/", 15 | }); 16 | 17 | const queryClient = new QueryClient(); 18 | 19 | function TodoApp() { 20 | // const { data: todos } = useQuery("todos", getTodos, { 21 | // initialData: [], 22 | // }); 23 | const { data: todos } = useQuery( 24 | "todos", 25 | async () => (await axiosClient.get("/todos")).data, 26 | { 27 | initialData: [], 28 | } 29 | ); 30 | // const updateMutation = useMutation(updateTodo, { 31 | // onSuccess: () => queryClient.invalidateQueries("todos"), 32 | // }); 33 | const updateMutation = useMutation( 34 | (todo) => axiosClient.put(`/todos/${todo.id}`, todo), 35 | { 36 | onSettled: () => queryClient.invalidateQueries("todos"), 37 | } 38 | ); 39 | 40 | // const deleteMutation = useMutation(deleteTodo, { 41 | // onSuccess: () => queryClient.invalidateQueries("todos"), 42 | // }); 43 | const deleteMutation = useMutation( 44 | ({ id }) => axiosClient.delete(`/todos/${id}`), 45 | { 46 | onSettled: () => queryClient.invalidateQueries("todos"), 47 | } 48 | ); 49 | 50 | // const createMutation = useMutation(createTodo, { 51 | // onSuccess: () => queryClient.invalidateQueries("todos"), 52 | // }); 53 | const createMutation = useMutation( 54 | (data) => axiosClient.post("/todos", data), 55 | { 56 | onSettled: () => { 57 | queryClient.invalidateQueries("todos"); 58 | textRef.current!.value = ""; 59 | }, 60 | } 61 | ); 62 | 63 | const textRef = useRef(null); 64 | 65 | return ( 66 |
67 |
68 | {todos?.map((todo) => ( 69 | 70 |
71 | { 75 | updateMutation.mutate({ ...todo, done: !todo.done }); 76 | }} 77 | /> 78 | {todo.text} 79 |
80 | 87 |
88 | ))} 89 |
90 |
91 | 92 | 99 |
100 |
101 | ); 102 | } 103 | 104 | function App() { 105 | return ( 106 | 107 | 108 | 109 | 110 | ); 111 | } 112 | 113 | export default App; 114 | -------------------------------------------------------------------------------- /rq-todos/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | .App { 11 | max-width: 800px; 12 | margin: auto; 13 | font-size: 2rem; 14 | } 15 | 16 | input, button { 17 | font-size: 2rem; 18 | } 19 | 20 | .todos { 21 | display: grid; 22 | grid-template-columns: 80% 20%; 23 | row-gap: 0.5rem; 24 | } 25 | .todos input { 26 | padding-top: 0.5rem; 27 | } 28 | .todos input[type='checkbox'] { 29 | zoom: 2; 30 | } 31 | .todos button { 32 | background-color: white; 33 | border: 1px solid #ccc; 34 | border-radius: 5px; 35 | } 36 | 37 | .add { 38 | display: flex; 39 | flex-direction: row; 40 | margin-top: 1rem; 41 | } 42 | .add input { 43 | width: 100%; 44 | margin-right: 1rem; 45 | } 46 | .add button { 47 | min-width: 20%; 48 | background-color: blue; 49 | color: white; 50 | border: none; 51 | border-radius: 5px; 52 | } 53 | -------------------------------------------------------------------------------- /rq-todos/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /rq-todos/src/lib/api.ts: -------------------------------------------------------------------------------- 1 | export const BASE_URL = "http://localhost:4000/todos"; 2 | 3 | export interface Todo { 4 | id: number; 5 | text: string; 6 | active: boolean; 7 | done: boolean; 8 | } 9 | 10 | export const getTodos = async (): Promise => 11 | fetch(BASE_URL).then((res) => res.json()); 12 | 13 | export const getTodo = async (id: number): Promise => 14 | fetch(`${BASE_URL}/${id}`).then((res) => res.json()); 15 | 16 | export const createTodo = async (text: string): Promise => 17 | fetch(`${BASE_URL}`, { 18 | method: "POST", 19 | headers: { 20 | "Content-Type": "application/json", 21 | }, 22 | body: JSON.stringify({ 23 | text, 24 | }), 25 | }).then((res) => res.json()); 26 | 27 | export const updateTodo = async (todo: Todo): Promise => 28 | fetch(`${BASE_URL}/${todo.id}`, { 29 | method: "PUT", 30 | headers: { 31 | "Content-Type": "application/json", 32 | }, 33 | body: JSON.stringify(todo), 34 | }).then((res) => res.json()); 35 | 36 | export const deleteTodo = async (todo: Todo): Promise => 37 | fetch(`${BASE_URL}/${todo.id}`, { 38 | method: "DELETE", 39 | }).then(() => todo); 40 | -------------------------------------------------------------------------------- /rq-todos/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rq-todos/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /rq-todos/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /rq-todos/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /rq-todos/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /rtk-todos/.gitignore: -------------------------------------------------------------------------------- 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* 24 | -------------------------------------------------------------------------------- /rtk-todos/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /rtk-todos/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rtk-todos", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@reduxjs/toolkit": "^1.6.2", 7 | "@testing-library/jest-dom": "^5.11.4", 8 | "@testing-library/react": "^11.1.0", 9 | "@testing-library/user-event": "^12.1.10", 10 | "@types/jest": "^26.0.15", 11 | "@types/node": "^12.0.0", 12 | "@types/react": "^17.0.0", 13 | "@types/react-dom": "^17.0.0", 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-redux": "^7.2.5", 17 | "react-scripts": "4.0.3", 18 | "redux": "^4.1.1", 19 | "typescript": "^4.1.2", 20 | "web-vitals": "^1.0.1" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": [ 30 | "react-app", 31 | "react-app/jest" 32 | ] 33 | }, 34 | "browserslist": { 35 | "production": [ 36 | ">0.2%", 37 | "not dead", 38 | "not op_mini all" 39 | ], 40 | "development": [ 41 | "last 1 chrome version", 42 | "last 1 firefox version", 43 | "last 1 safari version" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rtk-todos/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jherr/rtk-query-vs-rq/20763efa13f5d1318cecb102551a681d39216520/rtk-todos/public/favicon.ico -------------------------------------------------------------------------------- /rtk-todos/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /rtk-todos/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jherr/rtk-query-vs-rq/20763efa13f5d1318cecb102551a681d39216520/rtk-todos/public/logo192.png -------------------------------------------------------------------------------- /rtk-todos/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jherr/rtk-query-vs-rq/20763efa13f5d1318cecb102551a681d39216520/rtk-todos/public/logo512.png -------------------------------------------------------------------------------- /rtk-todos/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /rtk-todos/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /rtk-todos/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /rtk-todos/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /rtk-todos/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useRef } from "react"; 2 | import { ApiProvider } from "@reduxjs/toolkit/query/react"; 3 | 4 | import { todoApi, Todo } from "./store"; 5 | 6 | function TodoApp() { 7 | const { data: todos } = todoApi.useGetAllQuery(); 8 | const [deleteTodo] = todoApi.useDeleteTodoMutation(); 9 | const [updateTodo] = todoApi.useUpdateTodoMutation(); 10 | const [addTodo] = todoApi.useAddTodoMutation(); 11 | 12 | const textRef = useRef(null); 13 | const onAdd = useCallback(() => { 14 | addTodo(textRef.current!.value ?? ""); 15 | textRef.current!.value = ""; 16 | }, [addTodo]); 17 | 18 | const onToggle = useCallback( 19 | (todo: Todo) => updateTodo({ ...todo, done: !todo.done }), 20 | [updateTodo] 21 | ); 22 | 23 | const onDelete = useCallback((todo: Todo) => deleteTodo(todo), [deleteTodo]); 24 | 25 | return ( 26 |
27 |
28 | {todos?.map((todo) => ( 29 | 30 |
31 | onToggle(todo)} 35 | /> 36 | {todo.text} 37 |
38 | 39 |
40 | ))} 41 |
42 |
43 | 44 | 45 |
46 |
47 | ); 48 | } 49 | 50 | function App() { 51 | return ( 52 | 53 | 54 | 55 | ); 56 | } 57 | 58 | export default App; 59 | -------------------------------------------------------------------------------- /rtk-todos/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | .App { 11 | max-width: 800px; 12 | margin: auto; 13 | font-size: 2rem; 14 | } 15 | 16 | input, button { 17 | font-size: 2rem; 18 | } 19 | 20 | .todos { 21 | display: grid; 22 | grid-template-columns: 80% 20%; 23 | row-gap: 0.5rem; 24 | } 25 | .todos input { 26 | padding-top: 0.5rem; 27 | } 28 | .todos input[type='checkbox'] { 29 | zoom: 2; 30 | } 31 | .todos button { 32 | background-color: white; 33 | border: 1px solid #ccc; 34 | border-radius: 5px; 35 | } 36 | 37 | .add { 38 | display: flex; 39 | flex-direction: row; 40 | margin-top: 1rem; 41 | } 42 | .add input { 43 | width: 100%; 44 | margin-right: 1rem; 45 | } 46 | .add button { 47 | min-width: 20%; 48 | background-color: blue; 49 | color: white; 50 | border: none; 51 | border-radius: 5px; 52 | } 53 | -------------------------------------------------------------------------------- /rtk-todos/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /rtk-todos/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rtk-todos/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /rtk-todos/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /rtk-todos/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /rtk-todos/src/store.ts: -------------------------------------------------------------------------------- 1 | import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; 2 | 3 | export interface Todo { 4 | id: number; 5 | text: string; 6 | active: boolean; 7 | done: boolean; 8 | } 9 | 10 | export const todoApi = createApi({ 11 | reducerPath: "todoApi", 12 | baseQuery: fetchBaseQuery({ baseUrl: "http://localhost:4000/" }), 13 | tagTypes: ["Todos"], 14 | endpoints: (builder) => ({ 15 | getAll: builder.query({ 16 | query: () => `todos`, 17 | providesTags: [{ type: "Todos", id: "LIST" }], 18 | }), 19 | addTodo: builder.mutation({ 20 | query(text) { 21 | return { 22 | url: `todos`, 23 | method: "POST", 24 | body: { 25 | text, 26 | }, 27 | }; 28 | }, 29 | invalidatesTags: [{ type: "Todos", id: "LIST" }], 30 | }), 31 | updateTodo: builder.mutation({ 32 | query(todo) { 33 | return { 34 | url: `todos/${todo.id}`, 35 | method: "PUT", 36 | body: todo, 37 | }; 38 | }, 39 | invalidatesTags: [{ type: "Todos", id: "LIST" }], 40 | }), 41 | deleteTodo: builder.mutation({ 42 | query(todo) { 43 | return { 44 | url: `todos/${todo.id}`, 45 | method: "DELETE", 46 | body: todo, 47 | }; 48 | }, 49 | invalidatesTags: [{ type: "Todos", id: "LIST" }], 50 | }), 51 | }), 52 | }); 53 | -------------------------------------------------------------------------------- /rtk-todos/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /server/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | sourceType: 'module', 6 | }, 7 | plugins: ['@typescript-eslint/eslint-plugin'], 8 | extends: [ 9 | 'plugin:@typescript-eslint/recommended', 10 | 'plugin:prettier/recommended', 11 | ], 12 | root: true, 13 | env: { 14 | node: true, 15 | jest: true, 16 | }, 17 | ignorePatterns: ['.eslintrc.js'], 18 | rules: { 19 | '@typescript-eslint/interface-name-prefix': 'off', 20 | '@typescript-eslint/explicit-function-return-type': 'off', 21 | '@typescript-eslint/explicit-module-boundary-types': 'off', 22 | '@typescript-eslint/no-explicit-any': 'off', 23 | }, 24 | }; 25 | -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json -------------------------------------------------------------------------------- /server/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /server/README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logo 3 |

4 | 5 | [circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 6 | [circleci-url]: https://circleci.com/gh/nestjs/nest 7 | 8 |

A progressive Node.js framework for building efficient and scalable server-side applications.

9 |

10 | NPM Version 11 | Package License 12 | NPM Downloads 13 | CircleCI 14 | Coverage 15 | Discord 16 | Backers on Open Collective 17 | Sponsors on Open Collective 18 | 19 | Support us 20 | 21 |

22 | 24 | 25 | ## Description 26 | 27 | [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. 28 | 29 | ## Installation 30 | 31 | ```bash 32 | $ npm install 33 | ``` 34 | 35 | ## Running the app 36 | 37 | ```bash 38 | # development 39 | $ npm run start 40 | 41 | # watch mode 42 | $ npm run start:dev 43 | 44 | # production mode 45 | $ npm run start:prod 46 | ``` 47 | 48 | ## Test 49 | 50 | ```bash 51 | # unit tests 52 | $ npm run test 53 | 54 | # e2e tests 55 | $ npm run test:e2e 56 | 57 | # test coverage 58 | $ npm run test:cov 59 | ``` 60 | 61 | ## Support 62 | 63 | Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). 64 | 65 | ## Stay in touch 66 | 67 | - Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) 68 | - Website - [https://nestjs.com](https://nestjs.com/) 69 | - Twitter - [@nestframework](https://twitter.com/nestframework) 70 | 71 | ## License 72 | 73 | Nest is [MIT licensed](LICENSE). 74 | -------------------------------------------------------------------------------- /server/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "server", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "private": true, 7 | "license": "UNLICENSED", 8 | "scripts": { 9 | "prebuild": "rimraf dist", 10 | "build": "nest build", 11 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 12 | "start": "nest start", 13 | "start:dev": "nest start --watch", 14 | "start:debug": "nest start --debug --watch", 15 | "start:prod": "node dist/main", 16 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 17 | "test": "jest", 18 | "test:watch": "jest --watch", 19 | "test:cov": "jest --coverage", 20 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 21 | "test:e2e": "jest --config ./test/jest-e2e.json" 22 | }, 23 | "dependencies": { 24 | "@nestjs/common": "^8.0.0", 25 | "@nestjs/core": "^8.0.0", 26 | "@nestjs/platform-express": "^8.0.0", 27 | "class-validator": "^0.13.1", 28 | "reflect-metadata": "^0.1.13", 29 | "rimraf": "^3.0.2", 30 | "rxjs": "^7.2.0" 31 | }, 32 | "devDependencies": { 33 | "@nestjs/cli": "^8.0.0", 34 | "@nestjs/schematics": "^8.0.0", 35 | "@nestjs/testing": "^8.0.0", 36 | "@types/express": "^4.17.13", 37 | "@types/jest": "^27.0.1", 38 | "@types/node": "^16.0.0", 39 | "@types/supertest": "^2.0.11", 40 | "@typescript-eslint/eslint-plugin": "^4.28.2", 41 | "@typescript-eslint/parser": "^4.28.2", 42 | "eslint": "^7.30.0", 43 | "eslint-config-prettier": "^8.3.0", 44 | "eslint-plugin-prettier": "^3.4.0", 45 | "jest": "^27.0.6", 46 | "prettier": "^2.3.2", 47 | "supertest": "^6.1.3", 48 | "ts-jest": "^27.0.3", 49 | "ts-loader": "^9.2.3", 50 | "ts-node": "^10.0.0", 51 | "tsconfig-paths": "^3.10.1", 52 | "typescript": "^4.3.5" 53 | }, 54 | "jest": { 55 | "moduleFileExtensions": [ 56 | "js", 57 | "json", 58 | "ts" 59 | ], 60 | "rootDir": "src", 61 | "testRegex": ".*\\.spec\\.ts$", 62 | "transform": { 63 | "^.+\\.(t|j)s$": "ts-jest" 64 | }, 65 | "collectCoverageFrom": [ 66 | "**/*.(t|j)s" 67 | ], 68 | "coverageDirectory": "../coverage", 69 | "testEnvironment": "node" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /server/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { TodosModule } from './modules/todos/todo.module'; 3 | 4 | @Module({ 5 | imports: [TodosModule], 6 | }) 7 | export class AppModule {} 8 | -------------------------------------------------------------------------------- /server/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | app.enableCors(); 7 | await app.listen(4000); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /server/src/modules/todos/todo.controller.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Controller, 3 | Get, 4 | Post, 5 | Put, 6 | Delete, 7 | Body, 8 | Param, 9 | HttpCode, 10 | } from '@nestjs/common'; 11 | 12 | interface Todo { 13 | id: number; 14 | text: string; 15 | active: boolean; 16 | done: boolean; 17 | } 18 | 19 | let todos: Todo[] = [ 20 | 'NestJS', 21 | 'GraphQL', 22 | 'Apollo', 23 | 'TypeScript', 24 | 'React', 25 | 'Redux', 26 | 'React Query', 27 | 'Angular', 28 | 'Vue', 29 | 'D3', 30 | 'Svelte', 31 | 'SolidJS', 32 | 'NextJS', 33 | 'AWS', 34 | ].map((text, index) => ({ 35 | id: index + 1, 36 | text: `Learn ${text}`, 37 | active: true, 38 | done: false, 39 | })); 40 | 41 | @Controller('todos') 42 | export class TodosController { 43 | constructor() {} 44 | 45 | @Get() 46 | async index(): Promise { 47 | return todos.filter(({ active }) => active); 48 | } 49 | 50 | @Get(':id') 51 | async show(@Param('id') id: string): Promise { 52 | return todos.find((todo) => todo.id === parseInt(id)); 53 | } 54 | 55 | @Post() 56 | async create(@Body() { text }: { text: string }): Promise { 57 | const todo = { 58 | id: todos.length + 1, 59 | text, 60 | active: true, 61 | done: false, 62 | }; 63 | todos.push(todo); 64 | return todo; 65 | } 66 | 67 | @Put(':id') 68 | async update(@Param('id') id: string, @Body() data: Todo): Promise { 69 | todos = todos.map((todo) => 70 | todo.id === parseInt(id) ? { ...todo, ...data } : todo, 71 | ); 72 | 73 | return data; 74 | } 75 | 76 | @Delete(':id') 77 | @HttpCode(204) 78 | async destroy(@Param('id') id: string): Promise { 79 | todos = todos.map((todo) => 80 | todo.id === parseInt(id) ? { ...todo, active: false } : todo, 81 | ); 82 | return parseInt(id); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /server/src/modules/todos/todo.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | 3 | import { TodosController } from './todo.controller'; 4 | 5 | @Module({ 6 | controllers: [TodosController], 7 | }) 8 | export class TodosModule {} 9 | -------------------------------------------------------------------------------- /server/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /server/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /server/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true, 15 | "strictNullChecks": false, 16 | "noImplicitAny": false, 17 | "strictBindCallApply": false, 18 | "forceConsistentCasingInFileNames": false, 19 | "noFallthroughCasesInSwitch": false 20 | } 21 | } 22 | --------------------------------------------------------------------------------