-
Notifications
You must be signed in to change notification settings - Fork 0
/
dgraph-lambda.ts
28 lines (24 loc) · 1.06 KB
/
dgraph-lambda.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// You can type/paste your script here
async function newUserResolver({args, graphql}) {
let validationError = ""
if(!(/^([A-Za-z0-9._]{1,})$/.test(args.username))) validationError += "invalid username, "
if(!(/^([a-z0-9._]{10,})$/.test(args.password))) validationError += "invalid password, "
if(!(/^([a-z0-9._]{8,})$/.test(args.profile_image_hash))) validationError += "invalid profile_image_hash, "
if(!validationError){
const results = await graphql(`mutation customMutation {
addUser(input: {username: "${args.username}", profile_image_hash: "${args.profile_image_hash}", password: "${args.password}", thirdParty: {domain: "api.lorem.space", path: "image/face"}, joined_date:"${(new Date).toISOString()}"}) {
user {
id
}
}
}`)
console.log(JSON.stringify(results));
console.log("-----------------------------------");
return results.data.addUser.user[0].id
}else{
throw `validation fail code : ${validationError}`
}
}
self.addGraphQLResolvers({
"Mutation.newUser": newUserResolver
})