【发布时间】:2018-02-22 19:04:18
【问题描述】:
我的应用程序的目标是让用户能够保存和调用要填写和编辑的表单列表。一个用户将有许多表单,而一个表单将由它自己的多个字段组成。
如果我的类型是这样设置的,例如:
const FormType = new GraphQLObjectType({
name: 'FormType',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString },
email: { type: GraphQLString }
}
});
const UserType = new GraphQLObjectType({
name: 'UserType',
fields: {
id: { type: GraphQLID },
email: { type: GraphQLString },
firstName: { type: GraphQLString, default: '' },
lastName: { type: GraphQLString, default: '' },
phone: { type: GraphQLString, default: '' },
forms: { type: new GraphQLList(FormType) }
}
});
我的突变是这样的:
const mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
saveForm: {
type: UserType,
args: {
userID: { type: GraphQLID },
form: { type: FormType } // ???
},
resolve(parentValue, { userID, form }) {
// I'll figure out what to do here when the time comes
}
}
}
});
我似乎无法创建适用于GraphQLList 的突变。我不断收到此错误:
错误:Mutation.saveForm(form:) 参数类型必须是输入类型,但是 得到:FormType。
...我的研究告诉我,FormType 必须是GraphQLInputObjectType。当我相应地更改它时,我只是得到错误:
错误:Mutation.saveForm(form:) 参数类型必须是输出类型,但是 得到:FormType。
所以没有什么真正改变。有谁知道这个问题的工作示例?
【问题讨论】:
标签: javascript node.js mongoose graphql apollo