2

Here is a simple scenario
I want to query GraphQL and fetch all the students that have attended school more then 200 days this year.
I have a Student sequelize model, a matching GraphQL Object, a students Query which accepts the days int as an argument { students(days:200) }
What I'm obviously trying to do is to implement the logic "get all students where school_visits counter is greater than 200" just as an example...
I'm using graphql-sequelize to glue between sequelize and GraphQL.
a simple example query definition looks like this:

students: {
                type: new GraphQLList(Student),
                args:{
                    id  : {type:GraphQLInt}, 
                    days: {type:GraphQLInt}
                },
                resolve: resolver(models.Student)
            }

as you can notice, this structure doesn't allow me to insert some logic to the query... If you had any experience working with GraphQl and Sequelize - this is a very generic situation... I'd appreciate any help resolving it.
Cheers
Ajar

4

1 回答 1

4

查看Sequelize 文档,您可以尝试在学生解析函数中执行以下操作:

resolve(root, args) {
    // Assuming you've imported your model
    return Db.models.student.findAll({
        where: {
            days: {
                // greater than
                $gt: args.days
            }
        }
    });
}
于 2016-07-15T14:42:04.763 回答