1
我對於Graphql的遊標和MongoDB遊標之間的關係應該是什麼感到困惑。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
},
});
謝謝!