Skip to content

Instantly share code, notes, and snippets.

@rubycut
Last active October 8, 2017 16:57
Show Gist options
  • Save rubycut/aa61fc87784f70068b6af9faeec76da6 to your computer and use it in GitHub Desktop.
Save rubycut/aa61fc87784f70068b6af9faeec76da6 to your computer and use it in GitHub Desktop.
import {Cluster} from './cluster.js'
const graphqlFields = require('graphql-fields');
import * as _ from 'lodash'
const resolvers = {
Query: {
customer(root, args, context,info) {
var requested_fields = Object.keys(graphqlFields(info))
var c = Cluster.findForUser(context,args.id)
if(_.includes(requested_fields, 'contacts')) {
c = c.populate('contacts')
}
return c.then((data) => {
return [ data ]
}).catch(error => {
console.log(error)
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment