【问题标题】:NHOST TypeError: (intermediate value) is not a functionNHOST TypeError:(中间值)不是函数
【发布时间】:2022-11-04 23:08:57
【问题描述】:

以下来自 NHOST (https://docs.nhost.io/get-started/quick-start/javascript-client) 的代码:

import { NhostClient } from '@nhost/nhost-js'

const nhost = new NhostClient({
  backendUrl: 'https://[app-subdomain].nhost.run'
})(async () => {
  // nhost.graphql.request returns a promise, so we use await here
  const todos = await nhost.graphql.request(`
    query {
      todos {
        id
        created_at
        name
        is_completed
      }
    }
  `)

  // Print todos to console
  console.log(JSON.stringify(todos.data, null, 2))
})()

在终端中给我一个错误:

})(async () => {
  ^

TypeError: (intermediate value) is not a function
    at file:///Users/User/Documents/nhost-todos/index.js:5:3
    at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

它应该返回:

null

运行节点 index.js 后。

任何帮助将非常感激。这些对我来说都是相对较新的概念。

【问题讨论】:

    标签: javascript node.js terminal console nhost


    【解决方案1】:

    你可以这样做:

    import { NhostClient } from '@nhost/nhost-js';
    
    const nhost = new NhostClient({
      backendUrl: '',
    });
    
    const request = async () => {
      // nhost.graphql.request returns a promise, so we use await here
      const todos = await nhost.graphql.request(`
          query {
            todos {
              id
              created_at
              name
              is_completed
            }
          }
        `);
    
      // Print todos to console
      console.log(JSON.stringify(todos.data, null, 2));
    };
    
    request();
    

    【讨论】:

    • 通过添加有关代码的作用以及它如何帮助 OP 的更多信息,可以改进您的答案。
    猜你喜欢
    • 2021-01-13
    • 2018-02-10
    • 2015-07-19
    • 2019-07-06
    • 2018-04-02
    • 2023-01-05
    • 2016-11-06
    • 1970-01-01
    • 2020-01-05
    相关资源
    最近更新 更多