我有一个graphQL RootQueryType
,目前看起来像这样:
const RootQueryType = new graphql.GraphQLObjectType({
name: 'RootQueryType',
fields: {
accounts: {
type: graphql.GraphQLList(Account),
description: 'A list of accounts matching the provided arguments.',
args: {
type: {
type: graphql.GraphQLString
},
country: {
type: graphql.GraphQLString
},
currency: {
type: graphql.GraphQLString
}
},
resolve: (obj, args) => {
if (args.country === 'US') {
db.USaccounts.query()
} else if (args.currency === 'GBP') {
db.UKaccounts.query()
} else if ...
}
}
}
});
基本上,我的决心将是一大组条件分支,它检查是否存在各种参数组合,并使用正确的args调用相应的DB或内部API端点。这是在graphQL中处理参数的正确方法吗?