I'm wondering why my arguments seem to be switched around inside my GraphQL resolver. I'm using express-graphql.
Example of one resolver:
getLocalDrivers: async (parent, args, ctx) => {
console.log(ctx);
}
I've written the argument names as they appear in the docs: http://graphql.org/learn/execution/
But when I debug and inspect the objects, it seems the args object is 1st, the context is 2nd, and the parent/root is 3rd.
parent:
Object {location: "020202"}
args:
IncomingMessage {_readableState: ReadableState, readable: false, domain: null, …}
context:
Object {fieldName: "getLocalDrivers", fieldNodes: ....
Some server code:
app.use(
"/graphql",
graphqlHTTP({
schema,
graphiql: true,
rootValue: rootResolver
})
);
My 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
}`);