"Syntax Error: Expected Name, found \")\".",

"Syntax Error: Expected Name, found \")\".",

总的来说,我是 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"
} 

正确答案:

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

    type Query{
        events: Message
    }   `);

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