我目前正在尝试从 nodejs 中的 Apollo 服务器切换到 Graphene 服务器,但是在变异时遇到了问题。
客户端处理
const GeneratedForm = Form.create()(IngredientCategoryForm)
const createCategoryMut = gql`
mutation createCategoryMut($name: String) {
createCategory(name:$name) {
category {
name
}
}
}
`
const createCategoryWithApollo = graphql(createCategoryMut)(GeneratedForm)
export { createCategoryWithApollo as CategoryForm }
我正在以这种方式变异:
handleSubmit = (e) => {
const {
mutate
} = this.props
e.preventDefault()
this.props.form.validateFields((err, values) => {
if (!err) {
mutate({
variables: { name: 'myName' }
})
.then(({ data }) => {
console.log('got data', data);
}).catch((error) => {
console.log('there was an error sending the query', error);
})
}})
}
服务器端突变
类 CreateCategory(graphene.Mutation): 类参数: name = graphene.String()
category = graphene.Field(lambda: Category)
def mutate(self, info, name='toto'):
category = Category(name=name)
return CreateCategory(category=category)