【发布时间】:2019-01-07 09:53:24
【问题描述】:
不知道我做错了什么,但我在点击提交按钮后收到以下错误消息:
TypeError: this.props.ObjectQuery 不是函数
查询代码如下:
const ObjectQuery = gql`
query($timestamp: Float!){
action(timestamp: $timestamp){
action
timestamp
object{
filename
}
}
}
`;
class UserList extends React.Component {
render() {
return (
({ loading, error, data }) => {
if (loading) return <p>Loading...</p>;
if (error) {
console.log(error);
return <p>Error</p>;
}
if (data.action.length === 0) return <div>No Objects</div>;
return (//this code binds the query above to the output and puts it on the screen.
<Item.Group divided>
{data.action.map(action => (
<div>
<ul>
<li key = {action.action}>{action.action}</li>
<li key = {action.timestamp}>{action.timestamp}</li>
<ul>
{action.object.map((obj) => {
return (<li>{obj.filename}</li>)
})}
</ul>
</ul>
</div>
))}
</Item.Group>
);
}
)};
}
export default graphql(ObjectQuery, {
options: (props) => ({variables: {timestamp: props.timestamp}})
})(UserList);
这是提交按钮的代码。另外,由于某种原因,import 语句是灰色的。
import ObjectQuery from '../UserList';
handleSubmit(event) {
event.preventDefault();
console.log(this.state)
this.setState({ inputValue: new Date(document.getElementById("time").value ).valueOf() });
this.props.ObjectQuery({
variables:{
timestamp: this.state.inputValue
},
});
}
【问题讨论】:
-
@riyajkhan 你做了哪些修改?努力学习平台。另外,当我尝试使用 @ 时,你的名字没有得到解决。
-
添加了与特定 GraphQL 问题相关的 graphql 标签