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