我从graphql error教程开始学习graphql和reactjs并修改它。 现在我在尝试调用gql时遇到此错误: {{3}}
这是执行调用的类:
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;
查询graphql会返回所有数据,但现在当我尝试添加新数据时,我无法获取任何数据。 我在代码中做错了什么,或者这是graphql-tag的问题?
由于