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 jwt = require('jsonwebtoken') | |
| const config = require('./config') | |
| module.exports = async req => { | |
| // check for token in headers | |
| const token = req.headers.authorization | |
| try { | |
| const {user} = await jwt.verify(token, config.SECRET) | |
| // asign the user to req.user | |
| req.user = user |
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 express = require('express') | |
| const bodyParser = require('body-parser') | |
| const mongoose = require('mongoose') | |
| const cors = require('cors') | |
| const {graphiqlExpress, graphqlExpress} = require('apollo-server-express') | |
| const morgan = require('morgan') | |
| // require app modules | |
| const config = require('./config/config') | |
| const schema = require('./graphql') |
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
| module.exports = { | |
| Query: { | |
| hello (root, args, context) { | |
| return 'Hello World!!' | |
| } | |
| }, | |
| Mutation: { | |
| async createUser (root, args, {DB}) { | |
| const {username, email, password} = args | |
| const user = await DB.User.createUser(email, username, password) |
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
| module.exports = ` | |
| type User { | |
| id: ID! | |
| email: String! | |
| username: String! | |
| password: String! | |
| createAt: String! | |
| } | |
| type Query { | |
| hello : String! |
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 User = require('./user') | |
| module.exports = { | |
| User | |
| } |
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 mongoose = require('mongoose') | |
| const bcryptjs = require('bcryptjs') | |
| const jwt = require('jsonwebtoken') | |
| const config = require('../config/config') | |
| // user schema | |
| const userSchema = new mongoose.Schema({ | |
| username: { | |
| type: String, | |
| required: 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 {makeExecutableSchema} = require('graphql-tools') | |
| const resolvers = require('./resolvers') | |
| const typeDefs = require('./typeDefs') | |
| module.exports = makeExecutableSchema({ | |
| typeDefs, | |
| resolvers | |
| }) |
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
| module.exports = { | |
| Query: { | |
| hello (root, args, context) { | |
| return 'Hello world!!' | |
| } | |
| } | |
| } |
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
| module.exports = ` | |
| type Query { | |
| hello: String! | |
| } | |
| ` |
NewerOlder