简体   繁体   English

graphql 突变中无法识别的参数

[英]Unrecognized arguments in graphql mutation

I'm curretly following this tutorial on Meteor/Apollo/GraphQL, and having huge troubles to make a mutation with arguments/variables.我目前正在关注有关 Meteor/Apollo/GraphQL 的本教程,并且在使用参数/变量进行突变时遇到了巨大的麻烦。 Here is my code and some notes at the bottom !这是我的代码和底部的一些注释!

The code代码

Schema架构

type Resolution {
    _id: String!
    name: String!
}

type Mutation {
    createResolution(name: String!): Resolution
}

Resolver解析器

import Resolutions from './resolutions'

export default {
    Query: {
        resolutions() {
            return Resolutions.find({}).fetch()
        }
    },
    Mutation: {
        createResolution(obj, args, context) {
            console.log('hey i get here')
        }
    }
}

The component using the mutation使用突变的组件

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)

What i know我所知道的

  • When i try to send my query to the server, i get an http 400 error, and i get the following graphql error : "Unknown argument "name" on field "createResolution" of type "Mutation"."当我尝试将查询发送到服务器时,出现 http 400 错误,并且出现以下 graphql 错误:“Mutation”类型的字段“createResolution”上的“未知参数“name”。
  • The createResolution is available in my graphiQL but does not show any arguments in the doc. createResolution 在我的 graphiQL 中可用,但在文档中没有显示任何参数。
  • It's stipulated in the tutorial that changing the .graphql schema does not trigger meteor server reloading, to apply change i have to modify my "register-api" file which is responsible for making the executable schema and create the apollo server with it.教程中规定更改 .graphql 模式不会触发流星服务器重新加载,要应用更改,我必须修改我的“register-api”文件,该文件负责制作可执行模式并用它创建 apollo 服务器。 I made fake change to trigger it but it did not changed anything.我做了假改变来触发它,但它没有改变任何东西。
  • I tried to relaunch the server after erasing my browser's cache with no result.我试图在擦除浏览器缓存后重新启动服务器,但没有结果。

So I think my problem is with the mutation arguments (brilliant deduction I know), but I can't figure out where is the typo or where I'm missing something.所以我认为我的问题在于变异参数(我知道的精彩演绎),但我无法弄清楚错字在哪里或我在哪里遗漏了什么。 Help from somebody with a fresh look is welcome, thanks :)欢迎有新面貌的人提供帮助,谢谢:)

Edit编辑

Reinstall npm packages solved the issue.重新安装 npm 包解决了这个问题。

All looks good I made a small change and added it as a pull request to your github repo.一切看起来都不错,我做了一个小改动,并将其作为拉取请求添加到您的 github 存储库中。

createResolution(obj, {name}, context) {
        console.log('hey i get here')
        const id = Resolutions.insert({
            name,
        })
        return Resolutions.findOne(id)
    }

Running on my machine I get no errors.在我的机器上运行我没有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM