JoinMongo + Grapher + GraphQL = Awesomeness

Hi there

I’ve created a tiny package caled JoinMongo recently. It transform any GraphQL Query AST into a Mongo Field Specifier.

Why would you want to do that?

Because together with Grapher you can precisely query the fields and only fetch what you really need from MongoDB. Grapher also allows you to “link” collections, which means it’ll also resolve the nested fields.

import { Meteor } from 'meteor/meteor'
import transformAstToFieldSpecifiers from 'join-mongo'

const myAwesomeResolver = (args, context, root, ast) => {
  return Meteor.users.createQuery({
    ...transformAstToFieldSpecifiers(ast),
  }).fetch()
}

Here’s the same thing as a gist. Hope it’s useful!

8 Likes