我对 GraphQL 的游标和 MongoDB 的游标之间应该有什么关系感到困惑。
我目前正在研究创建对象(mongo 文档)并将其添加到现有连接(mongo 集合)的突变。添加对象时,突变返回添加的边缘。应该是这样的:
{
node,
cursor
}
虽然 node 是实际添加的文档,但我对应该作为光标返回的内容感到困惑。
这是我的突变:
const CreatePollMutation = mutationWithClientMutationId({
name: 'CreatePoll',
inputFields: {
title: {
type: new GraphQLNonNull(GraphQLString),
},
multi: {
type: GraphQLBoolean,
},
options: {
type: new GraphQLNonNull(new GraphQLList(GraphQLString)),
},
author: {
type: new GraphQLNonNull(GraphQLID),
},
},
outputFields: {
pollEdge: {
type: pollEdgeType,
resolve: (poll => (
{
// cursorForObjectInConnection was used when I've tested using mock JSON data,
// this doesn't work now since db.getPolls() is async
cursor: cursorForObjectInConnection(db.getPolls(), poll),
node: poll,
}
)),
},
},
mutateAndGetPayload: ({ title, multi, options, author }) => {
const { id: authorId } = fromGlobalId(author);
return db.createPoll(title, options, authorId, multi); //promise
},
});
谢谢!