我正在尝试执行搜索数据库的查询,并返回App组件上所有结果的数组。每次用户在表单中输入文本时都会触发该查询,但我不知道如何调用该查询,以便它将以该文本作为参数的结果并重新呈现该查询的结果以替换该查询。现有的渲染结果。当前,export语句中的graphql命令查询并将数据存储到应用程序的道具中。当用户输入信息时,我会在控制台中看到它,因为每次都会调用AssetAll函数。
我还想使用硬编码查询来初始化页面/组件。我正在使用反应阿波罗和 graphql-tag 模块。 预先感谢!
const AssetQueryInit = gql`
{
assetAll(assetName: "Worldpay Inc"){
_id
assetName
headline
firstCreated
sentimentNegative
sentimentPositive
sentimentNeutral
}
}`;
const AssetAllQuery = gql`
query($assetName: String!){
assetAll(assetName: $assetName){
_id
assetName
headline
firstCreated
sentimentNeutral
sentimentPositive
sentimentNegative
}
}
`;
class App extends Component {
AssetAll = (text) =>{
//query and re-render props
console.log(this.props);
};
render() {
const {
data : { loading, assetAll }
} = this.props;
console.log("rendering");
if(loading){
return null;
}
return (
<div className="App">
<Form submit ={this.AssetAll}/>
{assetAll.map(Asset => <div key= {Asset._id}>{Asset.headline}</div>)}
</div>
);
}
}
//export default App;
export default graphql(AssetQueryInit)(App);
//have a constructor that queries and loads results to avoid the undefined data error