Open marktani opened 6 years ago
Comment by lastmjs
Wednesday Jan 17, 2018 at 21:52 GMT
I'm having similar issues. As I try to deploy I always get "ensure that the code is valid".
Here is the only function I'm trying to push:
/*
Prendus took the source code and has modified it. Here is the original license
MIT License
Copyright (c) 2017 Graphcool Examples
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
const fromEvent = require('graphcool-lib').fromEvent;
const bcrypt = require('bcrypt');
const validator = require('validator');
export default async (event) => {
if (!event.context.graphcool.pat) {
console.log('Please provide a valid root token!')
return { error: 'signup not configured correctly.'}
}
const email = event.data.email
const password = event.data.password
const graphcool = fromEvent(event)
const api = graphcool.api('simple/v1')
const SALT_ROUNDS = 10
if (validator.isEmail(email)) {
return getGraphcoolUser(api, email)
.then(graphcoolUser => {
if (graphcoolUser === null) {
return bcrypt.hash(password, SALT_ROUNDS)
.then(hash => createGraphcoolUser(api, email, hash))
} else {
return Promise.reject("Email already in use")
}
})
.then(graphcoolUserId => {
return graphcool.generateAuthToken(graphcoolUserId, 'User')
.then(token => {
return { data: {id: graphcoolUserId, token}}
})
})
.catch((error) => {
console.log(error)
// don't expose error message to client!
return { error: 'An unexpected error occured.' }
})
} else {
return { error: "Not a valid email" }
}
}
function getGraphcoolUser(api, email) {
return api.request(`
query {
User(email: "${email}") {
id
}
}`)
.then((userQueryResult) => {
if (userQueryResult.error) {
return Promise.reject(userQueryResult.error)
} else {
return userQueryResult.User
}
})
}
function createGraphcoolUser(api, email, passwordHash) {
return api.request(`
mutation {
createUser(
email: "${email}",
password: "${passwordHash}"
) {
id
}
}`)
.then((userMutationResult) => {
return userMutationResult.createUser.id
})
}
Comment by lastmjs
Wednesday Jan 17, 2018 at 22:01 GMT
It seems like if I get rid of the default export, then it works. But without the export I'm not sure how Graphcool is going to call my code.
Comment by marktani
Thursday Jan 18, 2018 at 13:52 GMT
Does this occur when actually deploying, or when doing a dry run deployment?
Comment by wokalski
Friday Jan 19, 2018 at 19:08 GMT
I haven't had this error since upgrading graphcool-framework
I've upgraded to graphcool-framework, and I still get the error on a --dry-run
Thanks @lastmjs, I just updated the description to reflect that.
@marktani was this fixed? I'm also seeing this error on a --dry-run
after upgrading graphcool-framework
.
Current behavior
After creating a project and deploying it locally, I've played with it a bit, added some functions and everything was fine. I modified them once or twice. However, the next time I modified them I got
ensure that the code is valid
whatever I did. Even if the body of the function was as simple as it could be. (Likef (x) { return x }
for operationBefore).I even removed all functions and left only the ones that have not been previously modified but the error persisted.
The bottom line is that it seems that it's quite easy (but not obvious how) to cause some invalid internal state which causes this issue. After removing all docker images and data connected to them, I could successfully deploy the functions.
Reproduction
I'm very sorry - I don't have a reproducible case but I did my best to describe the issue.
Expected behavior?
The functions should just be created/updated