如何将变量传递给石墨烯的Apollo Mutation?

时间:2017-12-27 00:19:38

标签: apollo react-apollo graphene-python

我目前正在尝试从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 }

enter image description here

enter image description here

我正在改变这种方式:

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);
      })
  }})
}

服务器端Mutation

类CreateCategory(graphene.Mutation):     class参数:         name = graphene.String()

category = graphene.Field(lambda: Category)

def mutate(self, info, name='toto'):
    category = Category(name=name)
    return CreateCategory(category=category)

0 个答案:

没有答案