How in graphql.js get last 3 created_at element from mysql db table? I use sequelize.js
Like this:
query: '{
elements(last:3){
id
}
}'
This is my file db.js
const Conn = new Sequelize(/*connection config*/);
Conn.define('elements', {
id: {
type: Sequelize.STRING(36),
primaryKey: true,
allowNull: false
}
});
export default Conn;
This is my file schema.js
const Query = new GraphQLObjectType({
name: 'Query',
description: 'Root query object',
fields() {
return {
elements: {
type: new GraphQLList(Element),
args: {
id: {
type: GraphQLString
}
},
resolve (root, args) {
return Db.models.elements.findAll({ where: args });
}
}
}
}
});
it must be like this;
...
return Db.models.elements.findAll({
limit: 3,
where: args,
order: [['created_at', 'DESC']]
});
http://docs.sequelizejs.com/manual/tutorial/querying.html#pagination-limiting http://docs.sequelizejs.com/manual/tutorial/querying.html#ordering
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With