"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
}   `);

在浏览器中,您删除所有没有args的((

相关内容

最新更新