我目前正在关注Meteor / Apollo / GraphQL上的this tutorial,并且在使用参数/变量进行突变方面存在巨大麻烦。这是我的代码和底部的一些注释!
type Resolution {
_id: String!
name: String!
}
type Mutation {
createResolution(name: String!): Resolution
}
import Resolutions from './resolutions'
export default {
Query: {
resolutions() {
return Resolutions.find({}).fetch()
}
},
Mutation: {
createResolution(obj, args, context) {
console.log('hey i get here')
}
}
}
import React, { Component } from 'react'
import gql from 'graphql-tag'
import { graphql } from 'react-apollo'
const createResolutionQuery = gql`
mutation createResolution($name: String!) {
createResolution(name: $name) {
_id
}
}
`
class ResolutionForm extends Component {
submitForm = () => {
this.props
.createResolution({
variables: {
name: this.name.value
}
})
.then(d => console.log('data received'))
.catch(e => console.log(e))
}
render() {
return (
<div>
<input type="text" ref={input => (this.name = input)} />
<button onClick={this.submitForm}>Submit</button>
</div>
)
}
}
export default graphql(createResolutionQuery, {
name: 'createResolution'
})(ResolutionForm)
所以我认为我的问题在于变异论点(我知道的精彩演绎),但我无法弄清楚错字在哪里或者我错过了什么。欢迎来自新鲜面孔的人的帮助,谢谢:)
重新安装npm包解决了这个问题。
答案 0 :(得分:1)
一切看起来不错我做了一个小改动,并将其作为拉取请求添加到你的github回购。
createResolution(obj, {name}, context) {
console.log('hey i get here')
const id = Resolutions.insert({
name,
})
return Resolutions.findOne(id)
}
在我的机器上运行我没有错误。