[SOLVED] Adding columns to a Schema with a Resolver

Hi guys, its me again (i’ve been posting a lot lately!)

In this occasion im testing Apollo/Meteor and im trying to add to a Schema a new column that have a COUNT of the numer of rows (Im using Sequelize)

my schema looks like this (example):

type Colors {
    id: Int!
    color: String
    counter_colum: Int  <--- (column not present in the DB)
}

and my resolver:

  RootQuery: {
    colors(root, args){
      return Colors.findAll({
         where: args,
         attributes: [
           'id',
           'color',
           [sequelize.fn('COUNT', sequelize.col('color')), 'counter_column']
         ],
         group: ['color']
      });
    },
  },

But seems to not work at all :confused: “counter_column” returns null

am i missing something ?

Thanks Guys ! :smiley:


EDIT: I solved


I just added on my connector the column

(its was out of logic for me because it is not present on the DB, but it actually is because it triggers a new column on the request query)

counter_column: {
    type: Sequelize.INTEGER
 }

and it works like a charm ! :slight_smile:

1 Like