【问题标题】:"Syntax Error: Expected Name, found \")\".","语法错误:预期名称,找到\")\"。",
【发布时间】:2023-03-31 04:23:01
【问题描述】:

总的来说,我是 graphql 和 js 的新手,尝试构建尽可能多的练习来学习。我做了以下事情:

var schema = buildSchema(`
    type Query{
        events(): Message
    }

    type Message{
        id: ID!
        random_nr: Int!
    }`);

class Message {

    calculate(){
        var output = [];
        var id = Math.random().toString();
        var random_nr = Math.floor(Math.random() * 10);
        output.push(id);
        output.push(random_nr);
        return output;
        console.log(output);
         };
    }

    var root = {  events:()=>{ return new Message(); }}

然后在浏览器中执行:

{
  events(){
    calculate()
  }
}

收到标题错误,谁能给我点智慧之光。

更新:将() 添加到现在我收到的事件后:

{
  "message": "Failed to fetch",
  "stack": "TypeError: Failed to fetch"
} 

【问题讨论】:

  • 显然是以前的人,给出了错误的答案,可能对我投了反对票

标签: javascript arrays graphql dom-events


【解决方案1】:

正确答案:

var schema = buildSchema(`
    type Message{
        calculate: [Int]
    }

    type Query{
        events: Message
    }   `);

然后在浏览器中删除所有没有参数的 ()

【讨论】:

    猜你喜欢
    • 2021-12-09
    • 2019-04-05
    • 2018-06-28
    • 2019-11-12
    • 2020-04-18
    • 2022-01-15
    • 2020-10-03
    • 2021-07-28
    • 2021-02-27
    相关资源
    最近更新 更多