Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject updating a node if a specific condition is true #3

Open
marktani opened this issue May 24, 2017 · 1 comment
Open

Reject updating a node if a specific condition is true #3

marktani opened this issue May 24, 2017 · 1 comment

Comments

@marktani
Copy link
Contributor

require('isomorphic-fetch')

module.exports = function (event, cb) {
  var endpoint = 'https://api.graph.cool/simple/v1/__PROJECT_ID__'
  var token = 'Bearer __PAT__'

  var postId = event.data.id
  console.log(event.data)
  
  var query = `{
    Post(id: "${postId}") {
      isPublished
    }
  }`

  return fetch(endpoint, {
    method: 'post',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': token
    },
    body: JSON.stringify({ query })
  }).then((response) => {
    return response.json()
  }).then((data) => {
    console.log(data)
    if (data.data.Post.isPublished) {
      console.log('all good')
      return event 
    } else {
      console.log(`Unexpected update for Post ${postId}`)
      return {error: "Post not open for editing!"} 
    }
  })
}
kbrandwijk pushed a commit to kbrandwijk/functions that referenced this issue Jun 26, 2017
Yus pr changes for encrypted-file-proxy
@kbrandwijk
Copy link
Contributor

How is this different from a PQ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants