简体   繁体   中英

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. 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"."
  • The createResolution is available in my graphiQL but does not show any arguments in the doc.
  • 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. 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.

All looks good I made a small change and added it as a pull request to your github repo.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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