Graphcool / graphcool-framework

Apache License 2.0
1.77k stars 131 forks source link

Functions cannot be deployed during dry run, failing with "ensure that the code is valid" #449

Open marktani opened 6 years ago

marktani commented 6 years ago

Issue by wokalski Friday Jan 05, 2018 at 10:20 GMT Originally opened as https://github.com/graphcool/prisma/issues/1512


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. (Like f (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

marktani commented 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
    })
}
marktani commented 6 years ago

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.

marktani commented 6 years ago

Comment by marktani Thursday Jan 18, 2018 at 13:52 GMT


Does this occur when actually deploying, or when doing a dry run deployment?

marktani commented 6 years ago

Comment by wokalski Thursday Jan 18, 2018 at 14:18 GMT


When actually locally deploying.

marktani commented 6 years ago

Comment by lastmjs Friday Jan 19, 2018 at 19:04 GMT


@marktani For me it is during a dry run

marktani commented 6 years ago

Comment by wokalski Friday Jan 19, 2018 at 19:08 GMT


I haven't had this error since upgrading graphcool-framework

lastmjs commented 6 years ago

I've upgraded to graphcool-framework, and I still get the error on a --dry-run

marktani commented 6 years ago

Thanks @lastmjs, I just updated the description to reflect that.

joelaguero commented 6 years ago

@marktani was this fixed? I'm also seeing this error on a --dry-run after upgrading graphcool-framework.