GraphQL field's resolver not getting called

dsh*_*iro 3 express graphql apollo-server

I'm using apollo-server and testing using GraphiQL in my browser. I set up my resolvers based on Apollo's GitHunt-API example, but the resolver on the field "review.extraStuff" never gets called.

Resolver

const rootResolvers = {
    review(root, args, context) {
        console.log('resolving review');
        return {'HasErrors': true}
    }
}

const extraStuff = (root, args, context) => {
    console.log('resolving extraStuff');
    return "yes";
}

rootResolvers.review.extraStuff = extraStuff;

export default {
    RootQuery: rootResolvers
};
Run Code Online (Sandbox Code Playgroud)

Schema

const Review = `
    type Review {
        HasErrors: Boolean
        extraStuff: String
    }
`

const RootQuery = `
    type RootQuery {
        review(id: String!): Review
    }
`;

const SchemaDefinition = `
    schema {
        query: RootQuery
    }
`;
Run Code Online (Sandbox Code Playgroud)

Query result from GraphiQL

来自GraphiQL的查询结果

Additional Info

I know that Apollo is aware of my extraStuff resolver because if I set "requireResolversForNonScalar" to true, I don't get a message telling me extraStuff is missing a resolve function. I've added logging to both the schema and the apolloExpress middleware and learned nothing.

dsh*_*iro 5

我的问题是我不明白您传递给makeExecutableSchema(来自 graphql-tools)的解析器需要将您的所有类型映射到它们自己的解析器。换句话说,在传递给makeExecutableSchema的解析器对象中,每种类型都应该有一个顶级条目。

这是我解决问题的方法:

解析器

const rootResolvers = {
    review(root, args, context) {
        console.log('resolving review');
        return {'HasErrors': true}
    }
}

const reviewResolvers = {
    extraStuff(root, args, context) {
        console.log('resolving extraStuff');
        return "yes";
    }
}

export default {
    RootQuery: rootResolvers
    Review: reviewResolvers
};
Run Code Online (Sandbox Code Playgroud)

我的架构或其他任何地方都不需要更改。