GraphQL – 嵌套方法

我对GraphQL很陌生,想知道是否可以为types成员input单独的方法

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

这不起作用,因为GraphQL似乎不允许支持types成员的个别方法。 所以我testing这个时得到null 。 我的问题是:

是否有可能以这种方式嵌套方法,或者每次查询时都必须返回两个string?

编辑:

在NodeJS GraphiQL中testing

input查询

 { beitraege { beitr_name erst_name } } 

产量

 { "data": { "beitraege": null } } 

有我的错误:

而不是Beitrag: () =>它必须是beitraege: () =>因为我不想定义types成员,但模式成员。 我猜。