如何更改graphql中嵌套在数组中的对象的属性值?
我最近刚刚开始学习GraphQL,并决定在基于react的投票应用程序中实现它,用户可以在该应用程序中创建投票并对投票进行投票。 我创建了一个猫鼬模型,看起来像这样。 在编写Graphql时,我面临一个将投票添加到投票选项的问题。到目前为止,我的模式如下所示:如何更改graphql中嵌套在数组中的对象的属性值?,graphql,graphql-js,Graphql,Graphql Js,我最近刚刚开始学习GraphQL,并决定在基于react的投票应用程序中实现它,用户可以在该应用程序中创建投票并对投票进行投票。 我创建了一个猫鼬模型,看起来像这样。 在编写Graphql时,我面临一个将投票添加到投票选项的问题。到目前为止,我的模式如下所示: const AnswerType = new GraphQLObjectType({ name: "Answer", fields: () => ({ id: { type: GraphQLID }, opt
const AnswerType = new GraphQLObjectType({
name: "Answer",
fields: () => ({
id: { type: GraphQLID },
option: { type: GraphQLString },
votes: { type: GraphQLInt }
})
});
const QuestionType = new GraphQLObjectType({
name: "Question",
fields: () => ({
id: { type: new GraphQLNonNull(GraphQLID) },
question: { type: GraphQLString },
answer: { type: GraphQLList(AnswerType) }
})
});
const AnswerTypeInput = new GraphQLInputObjectType({
name: "AnswerInput",
fields: () => ({
option: { type: GraphQLString },
votes: { type: GraphQLInt }
})
});
const QuestionTypeInput = new GraphQLInputObjectType({
name: "QuestionInput",
fields: () => ({
question: { type: new GraphQLNonNull(GraphQLString) },
answer: { type: new GraphQLNonNull(GraphQLList(AnswerTypeInput)) }
})
});
const Mutation = new GraphQLObjectType({
name: "Mutation",
fields: {
addPoll: {
\\\\ code here
},
deletePoll: {
\\\\\ code here
},
upvotePoll: {
type: QuestionType,
args: { id: { type: new GraphQLNonNull(GraphQLID) } },
resolve(parent, args) {}
}
}
});
因此,我已经定义了我的类型,我可以添加和删除轮询并访问单个轮询(我跳过了这里的查询部分)。但我不知道如何访问单个poll的AnswerType对象,而不检索不必要的数据并使用它来编写我的upVote。
我希望有人能用这个来指导我