When we are using graphqlHTTP, the first argument passed to the resolve method is actually the parameters passed by the client query not root this is fine for a query resolv
Short answer: don't use buildSchema.
Passing resolve functions through the root value only works because it relies on the default resolver behavior, and it only works for root-level fields. Unfortunately, if you use buildSchema
, the only way to provide resolvers is through the root value.
Your options are:
Build your schema programatically instead of using Schema Definition Language (SDL). This will allow you to specify a resolve
function for any field in your schema, and that resolve function will get all four parameters (parent value, arguments, context and info). You can check out the docs for some examples.
Write your schema in SDL but use makeExecutableSchema
from graphql-tools
to generate your GraphQLSchema instance. makeExecutableSchema
allows you to painlessly inject resolvers for any fields and provides a number of other features. More information about how to generate a schema this way can be found here.
Dump express-graphql
for apollo-server
, which uses makeExecutableSchema
under the hood and provides a number of additional features that express-graphql
does not. Check the docs for how to get started.