Skip to content

Instantly share code, notes, and snippets.

@rubycut
Last active October 8, 2017 16:57

Revisions

  1. rubycut revised this gist Oct 8, 2017. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions resolver2.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    import {Cluster} from './cluster.js'
    const graphqlFields = require('graphql-fields');
    import * as _ from 'lodash'


    const resolvers = {
    Query: {
    customer(root, args, context,info) {
  2. rubycut revised this gist Oct 8, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions resolver2.js
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@ const resolvers = {
    var requested_fields = Object.keys(graphqlFields(info))
    var c = Cluster.findForUser(context,args.id)

    if(_.includes(requested_fields, 'groups')) {
    c = c.populate('groups')
    if(_.includes(requested_fields, 'contacts')) {
    c = c.populate('contacts')
    }

    return c.then((data) => {
  3. rubycut created this gist Oct 8, 2017.
    18 changes: 18 additions & 0 deletions resolver2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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, 'groups')) {
    c = c.populate('groups')
    }

    return c.then((data) => {
    return [ data ]
    }).catch(error => {
    console.log(error)
    });
    }
    }
    }