0

这是我的问题:

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
4

1 回答 1

2

在里面useQuery尝试将您的代码更改为:

variables: {
      input: GraphQuery,
    },
``
于 2020-04-20T13:22:35.307 回答