[英]Unrecognized arguments in graphql mutation
我目前正在关注有关 Meteor/Apollo/GraphQL 的本教程,并且在使用参数/变量进行突变时遇到了巨大的麻烦。 这是我的代码和底部的一些注释!
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 包解决了这个问题。
一切看起来都不错,我做了一个小改动,并将其作为拉取请求添加到您的 github 存储库中。
createResolution(obj, {name}, context) {
console.log('hey i get here')
const id = Resolutions.insert({
name,
})
return Resolutions.findOne(id)
}
在我的机器上运行我没有错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.