If you want to grant your NodeJS GraphQL service a whole lot of the power of the MongoDB database standing behind it with very little hassle, you've come to the right place!
You'll notice that integrating the package takes little more than adding some fancy middleware over the resolve function. The filter, projection, options added as the first parameters of the callback, can be sent directly to the MongoDB find function as shown. The rest of the parameter are the standard received from the GraphQL api.
Additionally, resolve fields' dependencies should be defined in the GraphQL type like so:
fullName: {type: GraphQLString,resolve: (obj,args,{ db })=>`${obj.name.first}${obj.name.last}`,dependencies: ['name']// or ['name.first', 'name.Last'], whatever tickles your fancy}
This is needed to ensure that the projection does not omit any necessary fields. Alternatively, if throughput is of no concern, the projection can be replaced with an empty object.
As of mongodb package version 3.0, you should implement the resolve callback as:
请发表评论