hpa*_*ier 5 reactjs graphql graphql-js react-apollo
当我使用 gql(来自“graphql-tag”)进行查询/突变/订阅时,出现错误。
\n有谁遇到过这个错误并且知道如何修复它?
\n这是我的代码:
import React from \'react\';\nimport { Mutation } from \'react-apollo\';\nimport MUTATION from \'./query.js\';\nimport gql from \'graphql-tag\';\n\nconst ADD_POST_MUTATION = gql`\n mutation addPost($content: String!, $author: String!)\xc2\xa0{\n addPost(content: $content, author: $author) {\n content\n author\n }\n }\n`;\n\nexport default class Tool extends React.Component {\n state = {\n content: \'\',\n author: localStorage.getItem(\'user\') || \'\'\n };\n\n handleSubmit = (e, mutation) => {\n console.log(mutation);\n e.preventDefault();\n mutation({ variables: { content: this.state.content, author: this.state.author }})\n .then(res => console.log(res))\n .catch(e => console.log(e));\n }\n\n render() {\n return (\n <Mutation mutation={MUTATION}>\n {(addPost, { data }) => (\n <div>\n <div>Poster un commentaire</div>\n <form onSubmit={e => this.handleSubmit(e, addPost)}>\n <textarea onChange={e => this.setState({ content: e.target.value })}></textarea>\n <button type=\'submit\'>Poster</button>\n </form>\n </div>\n )}\n </Mutation>\n );\n }\n};\nRun Code Online (Sandbox Code Playgroud)\n此查询再次出现错误:
\nconst FETCH_POST_QUERY = gql`\n query {\n getPost {\n id\n content\n author\n }\n }\n`;\nRun Code Online (Sandbox Code Playgroud)\n我收到这个错误:
\n\n| 归档时间: |
|
| 查看次数: |
7104 次 |
| 最近记录: |