"connectionArgs" 中继 js 的附加参数

Additional arguments to "connectionArgs" Relay js

例如我有连接类型:

let usersType = new GraphQLObjectType({
    name: 'Users',
    description: 'users array',
    fields: () => ({
        array: {
            type: userConnection,
            description: 'all users',
            args: connectionArgs,
            searchFor: {
                type: GraphQLString
            },
            resolve: (root, args) => {
                return connectionFromArray(get(), args);
            }
        }
    })
});

在这种情况下,在查询中我只能指定(第一个、最后一个、之后、之前)参数,但是如果我需要传递一些额外的参数,比如 userName 等,这可能吗?

基本上我需要这样的东西:

query {
    array (first: 1, userName: "name")
}

在用户类型中我可以处理这样的请求:

resolve: (root, args) => connectionFromArray(get(args.userName), args.args)

是的,这是可能的,您只需要使用如下新参数扩展中继助手 connectionArgs

args: {
   ...connectionArgs,
   searchFor: { type: GraphQLString }
}

然后在resolve函数中访问:

resolve: (root, args) => {
   // if the field argument 'searchFor' exists
   if (args.searchFor) {
   ...
   }
   ...
}