├── .DS_Store ├── README.md ├── final ├── .DS_Store ├── client │ ├── .env │ ├── .gitignore │ ├── Procfile │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ ├── server.js │ └── src │ │ ├── App.js │ │ ├── components │ │ ├── FileUpload.js │ │ ├── Image.js │ │ ├── LoadingToRedirect.js │ │ ├── Nav.js │ │ ├── PostCard.js │ │ ├── PostPagination.js │ │ ├── PrivateRoute.js │ │ ├── PublicRoute.js │ │ ├── Search.js │ │ ├── SearchResult.js │ │ ├── UserCard.js │ │ └── forms │ │ │ ├── AuthForm.js │ │ │ └── UserProfile.js │ │ ├── context │ │ └── authContext.js │ │ ├── firebase.js │ │ ├── graphql │ │ ├── fragments.js │ │ ├── mutations.js │ │ ├── queries.js │ │ └── subscriptions.js │ │ ├── index.css │ │ ├── index.js │ │ └── pages │ │ ├── Home.js │ │ ├── SingleUser.js │ │ ├── Users.js │ │ ├── auth │ │ ├── CompleteRegistration.js │ │ ├── Login.js │ │ ├── PasswordForgot.js │ │ ├── PasswordUpdate.js │ │ ├── Profile.js │ │ └── Register.js │ │ └── post │ │ ├── Post.js │ │ ├── PostUpdate.js │ │ └── SinglePost.js └── server │ ├── .DS_Store │ ├── .gitignore │ ├── Procfile │ ├── config │ └── fbServiceAccountKey.json │ ├── helpers │ └── auth.js │ ├── models │ ├── post.js │ └── user.js │ ├── package-lock.json │ ├── package.json │ ├── resolvers │ ├── auth.js │ └── post.js │ ├── server.js │ ├── temp.js │ └── typeDefs │ ├── auth.js │ └── post.js └── source_code_lecture_5-131.zip /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaloraat/graphql-react-node/0b194d2b11b594c430e1a83ec96cf0130228310e/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## GraphQL React Node MongoDB Firebase(Auth Only) Realtime MERN Stack Web App 2 | 3 | ## Source code for Udemy course 4 | 5 | [GraphQL from Scratch with React Node MongoDB Firebase MERN ](https://www.udemy.com/course/graphql-react-node/?couponCode=GRAPHQL) 6 | -------------------------------------------------------------------------------- /final/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaloraat/graphql-react-node/0b194d2b11b594c430e1a83ec96cf0130228310e/final/.DS_Store -------------------------------------------------------------------------------- /final/client/.env: -------------------------------------------------------------------------------- 1 | REACT_APP_GRAPHQL_ENDPOINT=http://localhost:8000/graphql 2 | REACT_APP_GRAPHQL_WS_ENDPOINT=ws://localhost:8000/graphql 3 | REACT_APP_REST_ENDPOINT=http://localhost:8000 4 | REACT_APP_CONFIRMATION_EMAIL_REDIRECT=http://localhost:3000/complete-registration 5 | REACT_APP_PASSWORD_FORGOT_REDIRECT=http://localhost:3000/login -------------------------------------------------------------------------------- /final/client/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | .env​ 4 | # dependencies 5 | /node_modules 6 | /.pnp 7 | .pnp.js 8 | 9 | # testing 10 | /coverage 11 | 12 | # production 13 | /build 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /final/client/Procfile: -------------------------------------------------------------------------------- 1 | web: node server.js -------------------------------------------------------------------------------- /final/client/README.md: -------------------------------------------------------------------------------- 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 | ### `yarn start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `yarn test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `yarn build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `yarn eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | 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. 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `yarn build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /final/client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.1.2", 4 | "private": true, 5 | "dependencies": { 6 | "@apollo/client": "^3.0.0-beta.43", 7 | "@apollo/react-hooks": "^3.1.4", 8 | "@testing-library/jest-dom": "^4.2.4", 9 | "@testing-library/react": "^9.3.2", 10 | "@testing-library/user-event": "^7.1.2", 11 | "apollo-boost": "^0.4.7", 12 | "apollo-link": "^1.2.14", 13 | "apollo-link-context": "^1.0.20", 14 | "apollo-link-ws": "^1.0.20", 15 | "apollo-utilities": "^1.3.3", 16 | "axios": "^0.19.2", 17 | "firebase": "^7.14.0", 18 | "graphql": "^15.0.0", 19 | "omit-deep": "^0.3.0", 20 | "react": "^16.13.1", 21 | "react-dom": "^16.13.1", 22 | "react-image-file-resizer": "^0.2.3", 23 | "react-router-dom": "^5.1.2", 24 | "react-scripts": "3.4.1", 25 | "react-snap": "^1.23.0", 26 | "react-toastify": "^5.5.0", 27 | "subscriptions-transport-ws": "^0.9.16" 28 | }, 29 | "scripts": { 30 | "start": "react-scripts start", 31 | "build": "react-scripts build", 32 | "test": "react-scripts test", 33 | "eject": "react-scripts eject", 34 | "postbuild": "react-snap" 35 | }, 36 | "eslintConfig": { 37 | "extends": "react-app" 38 | }, 39 | "browserslist": { 40 | "production": [ 41 | ">0.2%", 42 | "not dead", 43 | "not op_mini all" 44 | ], 45 | "development": [ 46 | "last 1 chrome version", 47 | "last 1 firefox version", 48 | "last 1 safari version" 49 | ] 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /final/client/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaloraat/graphql-react-node/0b194d2b11b594c430e1a83ec96cf0130228310e/final/client/public/favicon.ico -------------------------------------------------------------------------------- /final/client/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 17 | React App 18 | 19 | 20 | 21 |
22 | 27 | 32 | 37 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /final/client/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaloraat/graphql-react-node/0b194d2b11b594c430e1a83ec96cf0130228310e/final/client/public/logo192.png -------------------------------------------------------------------------------- /final/client/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaloraat/graphql-react-node/0b194d2b11b594c430e1a83ec96cf0130228310e/final/client/public/logo512.png -------------------------------------------------------------------------------- /final/client/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 | -------------------------------------------------------------------------------- /final/client/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /final/client/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const compression = require('compression'); 3 | const path = require('path'); 4 | const app = express(); 5 | 6 | app.use(compression()); 7 | app.use(express.static(path.join(__dirname, 'build'))); 8 | 9 | app.get('*', function(req, res) { 10 | res.sendFile(path.join(__dirname, 'build', 'index.html')); 11 | }); 12 | 13 | const PORT = process.env.PORT || 3000; 14 | 15 | app.listen(PORT, () => { 16 | console.log(`App is running on port ${PORT}`); 17 | }); 18 | -------------------------------------------------------------------------------- /final/client/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from 'react'; 2 | import { Switch, Route } from 'react-router-dom'; 3 | // from apollo boost 4 | // import ApolloClient, { InMemoryCache, HttpLink } from 'apollo-boost'; 5 | import ApolloClient from 'apollo-client'; 6 | import { InMemoryCache } from 'apollo-cache-inmemory'; 7 | import { HttpLink } from 'apollo-link-http'; 8 | // gql 9 | import { gql } from 'apollo-boost'; 10 | import { split } from 'apollo-link'; 11 | import { setContext } from 'apollo-link-context'; 12 | import { WebSocketLink } from 'apollo-link-ws'; 13 | import { getMainDefinition } from 'apollo-utilities'; 14 | 15 | import { ApolloProvider } from '@apollo/react-hooks'; 16 | import { ToastContainer } from 'react-toastify'; 17 | // import components 18 | import Nav from './components/Nav'; 19 | import Home from './pages/Home'; 20 | import Users from './pages/Users'; 21 | import Register from './pages/auth/Register'; 22 | import PasswordUpdate from './pages/auth/PasswordUpdate'; 23 | import PasswordForgot from './pages/auth/PasswordForgot'; 24 | import Profile from './pages/auth/Profile'; 25 | import Login from './pages/auth/Login'; 26 | import CompleteRegistration from './pages/auth/CompleteRegistration'; 27 | import { AuthContext } from './context/authContext'; 28 | import PrivateRoute from './components/PrivateRoute'; 29 | import PublicRoute from './components/PublicRoute'; 30 | import Post from './pages/post/Post'; 31 | import PostUpdate from './pages/post/PostUpdate'; 32 | import SinglePost from './pages/post/SinglePost'; 33 | import SingleUser from './pages/SingleUser'; 34 | import SearchResult from './components/SearchResult'; 35 | 36 | const App = () => { 37 | const { state } = useContext(AuthContext); 38 | const { user } = state; 39 | 40 | // 1. create websocket link 41 | const wsLink = new WebSocketLink({ 42 | uri: process.env.REACT_APP_GRAPHQL_WS_ENDPOINT, 43 | options: { 44 | reconnect: true 45 | } 46 | }); 47 | 48 | // 2. create http link 49 | const httpLink = new HttpLink({ 50 | uri: process.env.REACT_APP_GRAPHQL_ENDPOINT 51 | }); 52 | 53 | // 3. setContext for authtoken 54 | const authLink = setContext(() => { 55 | return { 56 | headers: { 57 | authtoken: user ? user.token : '' 58 | } 59 | }; 60 | }); 61 | 62 | // 4. concat http and authtoken link 63 | const httpAuthLink = authLink.concat(httpLink); 64 | 65 | // 5. use split to split http link or websocket link 66 | const link = split( 67 | ({ query }) => { 68 | // split link based on operation type 69 | const definition = getMainDefinition(query); 70 | return definition.kind === 'OperationDefinition' && definition.operation === 'subscription'; 71 | }, 72 | wsLink, 73 | httpAuthLink 74 | ); 75 | 76 | const client = new ApolloClient({ 77 | cache: new InMemoryCache(), 78 | link 79 | }); 80 | 81 | // const client = new ApolloClient({ 82 | // uri: process.env.REACT_APP_GRAPHQL_ENDPOINT, 83 | // request: (operation) => { 84 | // operation.setContext({ 85 | // headers: { 86 | // authtoken: user ? user.token : '' 87 | // } 88 | // }); 89 | // } 90 | // }); 91 | 92 | return ( 93 | 94 |