我正在构建一个API以查询MySQL数据库中的单个表。
我在表中有一个带有日期的字段。
我正在尝试获取日期范围之间的所有记录(类似于mysql的“ BETWEEN AND”语句。
const Person = new GraphQLObjectType({
name: 'Person',
Description: 'This represents a person',
fields: () => {
return {
firstName: {
type: GraphQLString,
resolve(bg) {
return bg.name;
}
},
middleName: {
type: GraphQLString,
resolve(bg) {
return bg.middleName;
}
},
lastName: {
type: GraphQLString,
resolve(bg) {
return bg.familyName;
}
},
dateOfBirth: {
type: GraphQLString,
resolve(bg) {
return bg.bornOn;
}
},
sex: {
type: GraphQLString,
resolve(bg) {
return bg.ses;
}
},
regCode: {
type: GraphQLString,
resolve(bg) {
return bg.regCode;
}
},
pinCode: {
type: GraphQLString,
resolve(bg) {
return bg.pinCode;
}
},
}
}
});
const dateOB = new GraphQLObjectType({
name: 'date',
Description: 'This represents a date interval',
fields: () => {
return {
between: {
type: GraphQLString,
},
and: {
type: GraphQLString,
}
}
}
});
const Query = new GraphQLObjectType({
name: 'query',
description: 'This is a root query',
fields: ()=> {
return {
people: {
type: new GraphQLList(Person, dateOB),
args: {
name: {
type: GraphQLString
},
familyName: {
type: GraphQLString
},
bornOn: {
type: GraphQLString
}
},
resolve(root, args) {
return Db.models.bg.findAll({where: args});
}
}
}
}
});
const Schema = new GraphQLSchema({
query: Query
});
我希望能够通过bornOn参数上的日期范围进行查询 例如“ 1972-05-05,2002-01-01”,因此它仅显示该范围内的记录。