graphql 突变中无法识别的参数
Unrecognized arguments in graphql mutation
我目前在 Meteor/Apollo/GraphQL 上关注 this tutorial,并且在 arguments/variables 上进行修改时遇到了很大的麻烦。这是我的代码和底部的一些注释!
密码
架构
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)
我所知道的
- 当我尝试将查询发送到服务器时,出现 http 400 错误,并且出现以下 graphql 错误:"Unknown argument "name" on field "createResolution" of type [=44] =]."
- createResolution 在我的 graphiQL 中可用,但在文档中没有显示任何参数。
- 教程中规定更改 .graphql 模式不会触发流星服务器重新加载,要应用更改,我必须修改我的 "register-api" 文件,该文件负责制作可执行模式并创建 apollo 服务器用它。我做了假的改变来触发它,但它没有改变任何东西。
- 我在清除浏览器缓存后尝试重新启动服务器,但没有结果。
所以我认为我的问题出在变异参数上(我知道精彩的推论),但我无法弄清楚错别字在哪里或我遗漏了什么。欢迎有新面貌的人帮忙,谢谢:)
编辑
重新安装 npm 包解决了问题。
一切看起来都不错我做了一个小改动并将其作为拉取请求添加到您的 github 存储库中。
createResolution(obj, {name}, context) {
console.log('hey i get here')
const id = Resolutions.insert({
name,
})
return Resolutions.findOne(id)
}
运行 在我的机器上没有错误。
我目前在 Meteor/Apollo/GraphQL 上关注 this tutorial,并且在 arguments/variables 上进行修改时遇到了很大的麻烦。这是我的代码和底部的一些注释!
密码
架构
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)
我所知道的
- 当我尝试将查询发送到服务器时,出现 http 400 错误,并且出现以下 graphql 错误:"Unknown argument "name" on field "createResolution" of type [=44] =]."
- createResolution 在我的 graphiQL 中可用,但在文档中没有显示任何参数。
- 教程中规定更改 .graphql 模式不会触发流星服务器重新加载,要应用更改,我必须修改我的 "register-api" 文件,该文件负责制作可执行模式并创建 apollo 服务器用它。我做了假的改变来触发它,但它没有改变任何东西。
- 我在清除浏览器缓存后尝试重新启动服务器,但没有结果。
所以我认为我的问题出在变异参数上(我知道精彩的推论),但我无法弄清楚错别字在哪里或我遗漏了什么。欢迎有新面貌的人帮忙,谢谢:)
编辑
重新安装 npm 包解决了问题。
一切看起来都不错我做了一个小改动并将其作为拉取请求添加到您的 github 存储库中。
createResolution(obj, {name}, context) {
console.log('hey i get here')
const id = Resolutions.insert({
name,
})
return Resolutions.findOne(id)
}
运行 在我的机器上没有错误。