100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > java js 解析器_graphqljs具有多个参数的解析器

java js 解析器_graphqljs具有多个参数的解析器

时间:2023-05-05 05:38:41

相关推荐

java js 解析器_graphqljs具有多个参数的解析器

我试图找出编写一个过滤多个参数的解析器的最佳方法 . 我有以下graphql类型

const userQuery = new GraphQLObjectType({

name: 'Query',

fields: {

Users: {

type: new GraphQLList(User),

args: {

userId: { type: GraphQLString }

},

resolve: function (_, { UserId}) {

return new Promise((resolve, reject) => {

//Code to query the data store for the user with the given UserId

})

}

}

}

});

用户类型具有以下字段

姓名

UserId

类型

性别

现在,如果我想介绍基于名称过滤用户的能力,那么最好的方法是什么 . 我能想到的唯一方法是修改解析器以包含其他args,然后根据传入的内容将其发送到数据库 . 例如

const userQuery = new GraphQLObjectType({

name: 'Query',

fields: {

Users: {

type: new GraphQLList(User),

args: {

userId: { type: GraphQLString }

},

resolve: function (_, { UserId, name}) {

return new Promise((resolve, reject) => {

//Check which argument is passed in and then run the query against the datastore

})

}

}

}

});

有没有更好的方法来做到这一点?如果我希望用户能够过滤另一个属性,那么它会变得更加复杂,并且解析功能将变得庞大而复杂 .

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。