I've got an apollo schema like this one:
type Batch {
Batch: String,
ItemCode: String,
PV: String,
ExpirationDate: DateTime,
Freezed: Boolean,
Item:Item,
Quantity: Float,
Fefo: Boolean
}
and a query in sequelize like that:
await models.Batch.findAll({
attributes: ['ItemCode','Lotto','ExpirationDate','Freezed', [Sequelize.literal(`CASE WHEN "Batch" ='${Batch}' THEN true ELSE false END`), "Fefo"] ],
where: whereClause,
include: [models.Item],
order: [
// Will escape title and validate DESC against a list of valid direction parameters
['ExpirationDate']
]
// attributes: models.mapAttribute(models.Batches, info)
})
returning an array of Batch
objects.
All runs without problems, graphql query works well:
{
getFefoBatches (ItemCode:"200200201",Batch:"20201118B")
{
Batch, ExpirationDate, Fefo, Item { ItemCode ItemName }
}
}
but the "Fefo" field is not valorized with the "sequelize.literal" value. It's always null.
Maybe I don't known the proper syntax, but I tried everything possible, and also I searched for a solution but without success.
How is it possible to make a correct mapping between sequelize field and Apollo server schema?
Thanks in advance.
attributes: ['id', [sequelize.literal('case when total_amount > 0 then 1 else 0 end'), 'test_alias']]
and it worked fine. – Anatoly