0
votes

I have the following graphql schema and I am trying to execute businessUser query

type Query {
  businessUser(id: String!): BusinessUser
}

type BusinessUser {
  id: ID!,
  firstName: String,
  lastName: String,
  email: String,
  posts: [BusinessPostFormat]
}

type BusinessPostFormat {
  postId: Int,
  user: String,
  isActive: Boolean,
  postText: String
}

In my resolver I am joining my Post table with my businessPost table to retrieve a 'isActive' column. When I print out what Sequilize is returning I see that I am getting back exactly the data object that should map to the BusinessPostFormat type:

post {
    dataValues: 
     { postId: '188',
       postText: 'blah blah blah',
       user: 'userName',
       isActive: false },

However when I execute the query in graphiql the isActive field is coming back as null. I dont understand why thats happening if I can see that the resolver is returning exactly what BusinessPostFormat type is expecting?

resolver function below:

const resolvers = {
  Query: {
    businessUser(_, args) {
      return BusinessUser.findById(args.id);
    }
},
BusinessUser: {
    posts(businessUser) {
      return businessUser.getPosts({
        attributes: {
          include: [[Sequelize.literal('business_posts.is_active'), 'isActive']],
          exclude: ['business_user_id']
        },
        include: [{ model: BusinessPost, attributes: ['is_active'] }]
      })
    },
  }
1

1 Answers

1
votes

Maybe you are missing the fact that Sequelize uses instances http://docs.sequelizejs.com/manual/tutorial/instances.html and maybe that is the missing fact in this case. Try it like this.

return Entries.findAll().then(entries => {
  return entries.map(e => e.get({ plain: true }));
})