Node.js GraphQL继电器返回一条记录

Node.js GraphQL继电器返回一条记录,node.js,graphql,graphql-relay,Node.js,Graphql,Graphql Relay,我在我的项目中使用graphql中继 在my grapgql中运行此查询时: { viewer{ boRelayCustomerInfo(_id:"59267769de82262d7e39c47c") { edges { node { id } } } } } 我给了这个错误: “消息”:“arraySlice.slice不是函数” 我的查询代码是: import { GraphQLID,

我在我的项目中使用graphql中继

在my grapgql中运行此查询时:

{
  viewer{
    boRelayCustomerInfo(_id:"59267769de82262d7e39c47c") {
      edges {
        node {
          id
        }
      }
    } 
  }
}
我给了这个错误:
“消息”:“arraySlice.slice不是函数”

我的查询代码是:

import {
  GraphQLID,
  GraphQLNonNull,
} from 'graphql'

import {
  connectionArgs,
  connectionFromPromisedArray,
} from 'graphql-relay'


import { customerConnection } from '@/src/schema/type/customer/CustomerType'
import { CustomerModel, ObjectId } from '@/src/db'


export default {
  type: customerConnection.connectionType,
  args: {
    ...connectionArgs,
    _id: {
      type: new GraphQLNonNull(GraphQLID),
    },
  },
  resolve: (_, args) => connectionFromPromisedArray(
    CustomerModel.findOne({_id: ObjectId(args._id)}),
    args,
  ),
}

请告诉我们,如何在中继中只返回一条记录。

如官方文件所述

连接来自PromisedArray接受解析为数组的承诺

因此,这里的问题是在connectionFromPromisedArray方法中传递的第一个参数。 即:
CustomerModel.findOne({u-id:ObjectId(args.\u-id)})

其中findOne返回一个对象,您需要使用find以数组的形式获取响应

问题代码:

  resolve: (_, args) => connectionFromPromisedArray(
    CustomerModel.findOne({_id: ObjectId(args._id)}), // <=== Error
    args,
  ),
 resolve: (_, args) => connectionFromPromisedArray(
    CustomerModel.find({_id: ObjectId(args._id)}), // <=== Solution
    args,
  ),
resolve:(u,args)=>connectionFromPromisedArray(
CustomerModel.findOne({\u-id:ObjectId(args.\u-id)}),//connectionFromPromisedArray(
CustomerModel.find({u-id:ObjectId(args.\u-id)})//