gpt4 book ai didi

javascript - 声明多个relayjs连接

转载 作者:行者123 更新时间:2023-12-01 04:07:49 25 4
gpt4 key购买 nike

我必须有两个 GraphQLObjectType

const AType = new GraphQLObjectType({
name: 'A'
fields: () => ({
id: globalIdField('A', obj => obj._id),
Id: {
type: GraphQLID,
resolve: obj => obj._id
},
email: { type: GraphQLString },
name: { type: GraphQLString },
status: { type: GraphQLString },
description: { type: GraphQLString }
}),
interfaces: [nodeInterface]
});

还有另一个类型 BType,我在 so t 的类型中使用 AType

const BType = new GraphQLObjectType({
name: 'BType',
fields: {
id: globalIdField('BType'),
ApplicantsDetails: {
type: AType,
resolve: obj => {
return obj.applicantsId;
}
},
respo_2: {
type: GraphQLString,
resolve: obj => "I have declared a ObjectType inside another"
}
},
interfaces: [nodeInterface]
});

以及我返回 promise 的主要类型,因此当我返回 promise resolve(d)时,它应该转到BType并且

const { connectionType: EmployerDashBoardConnectionType} =
connectionDefinitions({
name: 'EmployerDash',
nodeType: BType
});

以上是连接

        EmployerDashBoardConnection: {
type: EmployerDashBoardConnectionType,
description: 'Employer DashBoard Details',
args: connectionArgsWithJobId,
resolve: (_, args, auth) => {
return new Promise((resolve, reject) => {
Dash(_, args, auth, function (err, d) {
if (err) {
reject(err);
} else {
resolve(d);
}
});
});
}
}
/* Introduce your new fields here */
}

Dash() 函数调用的响应是

 {
applicantsId:
{ _id: 5878548b51179817f48eb1f1,
email: '123@gmail.com',
password: '$2a$10$lDpfl7kL4i/8VPij8aypmeeiD1794g1afACUxca397LdlErMgWa.S',
__v: 0,
name: 'Alpaina',
status: 'Unemployed',
isJobSeeker: true,
to: 2017-01-13T04:16:11.755Z }
}

它只打印 null

enter image description here

最佳答案

要使用边缘,您需要传递一个数组来解析函数

resolve: (_, args, auth) => {
return new Promise((resolve, reject) => {
Dash(_, args, auth, function (err, d) {
if (err) {
reject(err);
} else {
// if d is object then
const a = [];
a.push(d);
resolve(connectionFromArray(a, args));
}
});
});
}

这段代码只是为了解决你当前的问题

注意:使用中继连接时,您应该始终解析列表[ ]

关于javascript - 声明多个relayjs连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41681135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com