Halkeand
Halkeand

Reputation: 67

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

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.

Upvotes: 4

Views: 2163

Answers (1)

Sean Hayes
Sean Hayes

Reputation: 351

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.

Upvotes: 2

Related Questions