Skip to content

Commit

Permalink
feat: add graphql batching example
Browse files Browse the repository at this point in the history
  • Loading branch information
snoopysecurity committed Dec 15, 2021
1 parent 9a1351c commit d120c97
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions graphql/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fsPromise = require("fs").promises;
const bcrypt = require('bcrypt');
const Note = require('../models/notebook');
const User = require('../models/users');

const sql = require('../models/passphrase');


// A schema is a collection of type definitions (hence "typeDefs")
Expand Down Expand Up @@ -42,19 +42,25 @@ const GqtypeDefs = gql`
fileContent: String
}
type Passphrase {
passphrase: String
reminder: String
}
type Query {
userFindbyId(id: ID): User
userSearchByUsername(username: String): [User]
noteFindbyId(id: ID): Notebook
readNote(name: String): [Notebook]
getPassphrase(reminder: String): Passphrase
}
type Mutation {
updateUserUploadFile(filePath: String, fileContent: String): File
userLogin(username: String, password: String): User
createNote(name: String, body: String, type: [String]): [Notebook]
}
`;

Expand Down Expand Up @@ -82,14 +88,29 @@ const Gqresolvers = {

if ( typeof context.user == 'undefined' ){
throw new Error( "Missing JWT Admin Auth Token");
}

}
note = args.name;
result = await Note.find({ name: note }, 'name body user _id type').exec();
return result;
}


},
getPassphrase: async (parent, args, context, info) => {

var query = "select passphrase,reminder from passphrases WHERE reminder = " + sql.escape(args.reminder) + "";
let sqlInput;
await(new Promise((resolve, reject) => {
sql.query( query, function (err, result, fields) {
if (err) {
throw new Error(err);
resolve();
} else {

sqlInput = result;
resolve()
}
});
}));
return sqlInput[0];
},
},
Mutation: {
updateUserUploadFile: async (parent, args, context, info) => {
Expand Down Expand Up @@ -118,7 +139,6 @@ const Gqresolvers = {
if( result.length == 0 ) {
throw new Error( "User Login Failed");
}
console.log(result);
returnVar['username'] = result[0].username;
returnVar['password'] = result[0].password;

Expand Down

0 comments on commit d120c97

Please sign in to comment.