Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'TypeError: parse is not a function' when using gql

I started out with this tutorial to learn graphql and reactjs and modified it. Now I'm getting this error when trying to call gql: graphql error

This is the class that performs the call:

import React from 'react';
import gql from 'graphql-tag';
import { graphql } from 'react-apollo'

class BookForm extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            title: '',
            author: '',
            src: '',
        };
        this.handleChange = this.handleChange.bind(this);
        this.handleSubmit = this.handleSubmit.bind(this);
    }

    handleChange(event) {
        this.setState({[event.target.name]: event.target.value });
    }

    handleSubmit = (e) => {
        this.props.addBook({
            variables: {
                author: this.state.author,
                title: this.state.title,
                src: this.state.src
            }
        });
    }

    render() {
        return (
            <form className="book__form" onSubmit={this.handleSubmit}>
                <label>
                    Title:
                    <input type="text" name="title" value={this.srtate.title} onChange={this.handleChange} />
                </label>
                <label>
                    Author:
                    <input type="text" name="author" value={this.state.author} onChange={this.handleChange} />
                </label>
                <label>
                Src:
                <input type="text" name="src" value={this.state.src} onChange={this.handleChange}/>
                </label>
                <label>
                    <input type="submit" value="Submit" />
                </label>
            </form>
        );
    }
}


const addBook =  gql `mutation addBook ($author: String!, $title: String!, $: ID!) {
    addBook(author: $author, title: $title, src: $src) {
      id,
      author,
      title,
      src,
    }
  }`

const addBookWithMutation = graphql(addBook)(BookForm);
export default addBookWithMutation;

Query-ing graphql returns all the data but now when I'm trying to add new data I'm not getting anywhere. Am I doing something wrong in my code or is this a problem with graphql-tag?

Thanks

like image 659
Hjelmut4 Avatar asked Jan 30 '26 21:01

Hjelmut4


1 Answers

There seems to be a compatibility issue where version 0.13.1 of graphql-js breaks graphql-tag. You can fix by manually working around the versioning issues -

yarn add [email protected] [email protected] [email protected]

For reference, here is the issue on github

like image 74
Riggeot Avatar answered Feb 03 '26 11:02

Riggeot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!