[英]How in graphql get last 3 element
How in graphql.js get last 3 created_at element from mysql db table? graphql.js如何从mysql db表中获取最后3个created_at元素? I use sequelize.js
我用sequelize.js
Like this: 像这样:
query: '{
elements(last:3){
id
}
}'
This is my file db.js 这是我的文件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 这是我的文件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 http://docs.sequelizejs.com/manual/tutorial/querying.html#pagination-limiting http://docs.sequelizejs.com/manual/tutorial/querying.html#ordering
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.