[英]GraphQL - Nested Methods
I am very new to GraphQL and wonder if I can type individual methods for type members 我是GraphQL的新手,想知道是否可以为类型成员键入单个方法
var express = require('express');
var graphqlHTTP = require('express-graphql');
var { buildSchema } = require('graphql');
var schema = buildSchema(`
type Query {
beitraege: Beitrag
}
type Beitrag {
beitr_name: String
erst_name: String
}
`);
var root = {
// This is the part that does not work
Beitrag: () => {
beitr_name: () => {
return "Foo";
};
erst_name: () => {
return "Bar";
}
},
};
var app = express();
app.use("/graphql", graphqlHTTP({
schema: schema,
rootValue: root,
graphiql: true,
}));
app.listen(3000, "0.0.0.0", () => {
console.log("Started on port 3000");
});
This does not work as GraphQL seems do disallow to support individual methods for type-members. 这不起作用,因为GraphQL似乎不允许为类型成员支持单个方法。 So I get
null
while testing this. 所以我在测试时得到
null
。 My question is: 我的问题是:
Is there a possibility to nest methods in such a way or do I have to return both strings every time I make a query? 是否有可能以这种方式嵌套方法,或者我每次查询都必须返回两个字符串?
Edit: 编辑:
Tested in NodeJS GraphiQL 在NodeJS GraphiQL中测试
{
beitraege {
beitr_name
erst_name
}
}
{
"data": {
"beitraege": null
}
}
Got my mistake: 弄错了:
instead of Beitrag: () =>
it had to be beitraege: () =>
as I do not want to define type members but schema members. 而不是
Beitrag: () =>
它必须是beitraege: () =>
因为我不想定义类型成员,但要定义架构成员。 I guess. 我猜。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.