【发布时间】:2018-07-15 17:58:45
【问题描述】:
我想知道为什么我的论点似乎在我的 GraphQL 解析器中切换了。我正在使用 express-graphql。
一个解析器的示例:
getLocalDrivers: async (parent, args, ctx) => {
console.log(ctx);
}
我已经编写了文档中出现的参数名称:http://graphql.org/learn/execution/
但是当我调试和检查对象时,似乎 args 对象是第一个,上下文是第二个,父/根是第三个。
父母:
Object {location: "020202"}
参数:
IncomingMessage {_readableState: ReadableState, readable: false, domain: null, …}
上下文:
Object {fieldName: "getLocalDrivers", fieldNodes: ....
一些服务器代码:
app.use(
"/graphql",
graphqlHTTP({
schema,
graphiql: true,
rootValue: rootResolver
})
);
我的根解析器:
var rootResolver = {
getLocalDrivers: async (obj, args, ctx) => {
console.log(ctx);
}
}
架构:
var { buildSchema } = require("graphql");
var schema = buildSchema(`
type Query {
getLocalDrivers(location: String): [Driver]
}
type Driver {
name: String
location: String
}`);
【问题讨论】:
标签: graphql graphql-js express-graphql