嗨我有点新反应和graphql,一切都很好但我不知道如何将参数传递给查询
我需要一些帮助
import React from 'react';
import { gql, graphql } from 'react-apollo';
const CourseForm = ({ data: {loading, error, getData }}) => {
const testVariable = 2;
console.log(getData);
return (
<form >
<div className="form-group">
<label className="label-control">test</label>
<input type="text" className="form-control"/>
</div>
<button type="submit" className="btn btn-default">
Save
</button>
</form>);
}
const testQuery = gql`
query getData($id: Int!){
getData(id: $id) {
id, field {
id
}
}
}
`;
const test = graphql(
testQuery,{
options: { variables: { id: 1 } }}
)(CourseForm);
export default test;
&#13;
例如我如何在查询中使用testVariable值?获取id为2的数据
我看过一些使用ownProps的片段,但我不理解它,我应该使用道具吗?我觉得有点迷失
谢谢你们!
答案 0 :(得分:0)
您可以使用以下示例中的道具:
// The caller could do something like:
<ProfileWithData avatarSize={300} />
// And our HOC could look like:
const ProfileWithData = graphql(CurrentUserForLayout, {
options: ({ avatarSize }) => ({ variables: { avatarSize } }),
})(Profile);