这是我的问题:
const GraphComponent = () => {
const { GraphQuery } = useContext(GlobalContext);
const query = `
query($input: MeasurementQuery ){
getMeasurements(input: $input){
metric,
value,
unit,
at
}
}
`;
const [{ fetching, data, error }] = useQuery({
query,
variables: {
GraphQuery,
},
});
useEffect(() => {
const fun = () => {
if (fetching) return <p>Loading...</p>;
if (error) console.log(error.message);
if (!data) return;
console.log(data.getMeasurements);
};
fun();
}, [fetching, error, data]);
return <div></div>;
};
export default GraphComponent;
'GraphQuery' 变量是一个看起来像这样的对象
obj = {
metricName: deets,
after: Date.now() - 36000000,
before: Date.now(),
};
接受变量的 Playground 上的 graphql 查询如下所示
{
getMeasurements(input:{metricName:"tubingPressure", after:1587371198855,before:1587370098855}){
metric,
value,
unit,
at
}
}
但我不断得到的错误是
[GraphQL] Cannot read property 'metricName' of undefined