GraphCool TypeError: Converting circular structure to JSON

GraphCool TypeError: Converting circular structure to JSON

我从官方文档中复制粘贴了示例,希望我会看到一些不同的错误(无效的 URL 或无效的授权密钥或类似的东西)但是我得到了一些 webpack/sandbox 错误:

const fetch = require('isomorphic-fetch')
const Base64 = require('Base64')
const FormData =require('form-data')

const apiKey = '__MAILGUN_API_KEY__'
const url = '__MAILGUN_URL__'

export default event => {

  const form = new FormData()
  form.append('from', 'Nilan <nilan@graph.cool>')
  form.append('to', 'Nikolas <nikolas@graph.cool>')
  form.append('subject', 'Test')
  form.append('text', 'Hi')

  return fetch(url, {
    headers: {
      'Authorization': `Basic ${Base64.btoa(apiKey)}`
    },
    method: 'POST',
    body: form
  })
}

即使是简单的 API 请求也会失败:

require('isomorphic-fetch')

module.exports = function (event) {
  const url = 'https://jsonplaceholder.typicode.com/posts'
  return fetch(url)
}

上面的代码也是returns:

TypeError: Converting circular structure to JSON

at Object.stringify (native)

at /data/sandbox/lib/sandbox.js:532:48

at /data/io/8e0059b3-daeb-4989-972f-e0d88e27d15e/webtask.js:46:33

at process._tickDomainCallback (node.js:481:9)

如何从自定义 graphcool subscription/resolver 成功调用 API?

这是最简单的工作示例:

require('isomorphic-fetch')

module.exports = function (event) {
  const url = 'https://jsonplaceholder.typicode.com/posts'
  return fetch(url)
    .then(res => res.json())
    .then(data => {
      console.log(data)
      return {
        data: {
          sum: 3  
        }
      }
    })
}