我有以下查询:
import { gql } from 'apollo-boost';
const GetUserInfo = gql`
query getUserInfo($id: MongoID!){
userById(_id: $id){
local{
username
...
}
}
`;
export {GetUserInfo} ;
然后我将查询绑定到我的“React.Component”
import React from "react";
...
import { GetUserInfo } from "../../queries/queries";
import { graphql } from 'react-apollo';
class Dashboard extends React.Component {
constructor(props) {
super(props);
...
Dashboard.propTypes = {};
export default graphql(GetUserInfo, {
options: (props) => {
return {
variables: {
_id: props.ID
}
}
}
})(Dashboard);
我确定 props.ID 等同于 MongoDB ID。我也确定正在读取来自父组件的道具。
上面的代码导致以下错误:
[GraphQL 错误]:消息:所需类型“MongoID!”的变量“$id” 未提供。,位置:[object Object],路径:未定义
任何反馈将不胜感激。谢谢!