This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Todo() { | |
| const [tasks, setTasks] = useState([ | |
| { | |
| title: "Grab some Pizza", | |
| completed: true | |
| }, | |
| { | |
| title: "Do your workout", | |
| completed: true | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ReactDOM from "react-dom"; | |
| import React, { useReducer, useState } from "react"; | |
| const App = () => { | |
| const [data, setData] = useState(''); | |
| const [item, setItem] = useState([]); | |
| const HandleChange = (e) => { | |
| setData(e.target.value) | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ReactDOM from "react-dom"; | |
| import React, { useReducer, useRef } from "react"; | |
| const App = () => { | |
| const inputRef = useRef(); | |
| const [items, dispatch] = useReducer((state, action) => { | |
| switch (action.type) { | |
| case "ADD": | |
| return [ | |
| ...state, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const app = express(); | |
| app.use(bodyParser.json()); | |
| app.use( | |
| '/graphql', | |
| graphqlHttp({ | |
| schema: graphQlSchema, | |
| rootValue: graphQlResolvers, | |
| graphiql: true | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getLoggedInUser = req => { | |
| const token = req.headers['x-auth-token']; | |
| if (token) { | |
| try { | |
| return jwt.verify(token, process.env.JWT_SECRET); | |
| } catch(error) { | |
| throw new Error('Session expired'); | |
| } | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static registerUser(dbContext, payload) { | |
| return userHelper | |
| .findByEmail(dbContext, payload.email) | |
| .then(user => { | |
| if (!user) { | |
| const data = { ...payload, password: userHelper.hashPassword(payload.password) }; | |
| return dbContext.query(userModel.createUser(data)).then(() => { | |
| return Promise.resolve(null); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const resolvers = { | |
| Query: { | |
| users: (parent, args, { dbContext }) => { | |
| return userController.getAllUsers(dbContext); | |
| }, | |
| user: (parent, { email }, { dbContext }) => { | |
| return userController.getUserByEmail(dbContext, email); | |
| }, | |
| me: (parent, args, { me }) => me, | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { gql } = require('apollo-server-express'); | |
| module.exports = gql` | |
| extend type Query { | |
| users: [User] | |
| user(email: String!): User | |
| me: User | |
| } | |
| type Response { | |
| success: Boolean! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const server = new ApolloServer({ | |
| typeDefs, | |
| resolvers, | |
| context: ({ req }) => ({ | |
| dbContext: new Database(global.connection), | |
| me: getLoggedInUser(req), | |
| }), | |
| }); | |
| server.applyMiddleware({ app }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Object = { | |
| x : 90 | |
| } | |
| Object.defineProperty(Object,'getVal',{ | |
| get : function(){ | |
| return this.x; | |
| }, | |
| set : function(x){ | |
| this.x = x; |