Reactjs 如何从另一个组件重新提取graphql查询?

Reactjs 如何从另一个组件重新提取graphql查询?,reactjs,graphql,apollo,react-apollo,Reactjs,Graphql,Apollo,React Apollo,我对反应非常陌生,尤其是对graphql 每次使用Variation createEvent时,我都会尝试重新提取事件查询,因此包含所有事件的页面将自动更新,无需刷新 但是,我找不到连接这两个查询的方法 “form.jsx”文件中的事件: 这是我在“myTable.jsx”文件中的事件查询: 我在Promise'then'函数中尝试了refetchQueries函数,但它崩溃了。我从querys.js文件导出了查询,然后启用了使用ApolloClient的refetch选项 const bo

我对反应非常陌生,尤其是对graphql

每次使用Variation createEvent时,我都会尝试重新提取事件查询,因此包含所有事件的页面将自动更新,无需刷新

但是,我找不到连接这两个查询的方法

“form.jsx”文件中的事件:

这是我在“myTable.jsx”文件中的事件查询:


我在Promise'then'函数中尝试了refetchQueries函数,但它崩溃了。

我从querys.js文件导出了查询,然后启用了使用ApolloClient的refetch选项

  const body = {
    query:
      "mutation{" +
      "createEvent(eventInput:{num1:" +
      '"' +
      this.state.num1.toString() +
      '"' +
      ",num2:" +
      '"' +
      this.state.num2.toString() +
      '"' +
      "}){" +
      "_id " +
      "num1 " +
      "num2 " +
      "addition " +
      "multiply" +
      "}}"
  };
  fetch("https://localhost:8000/graphql", {
    method: "POST",
    body: JSON.stringify(body),
    headers: {
      "Content-Type": "application/json"
    }
  })
    .then(res => {
      if (res.status !== 200 && res.status !== 201) {
        throw new Error("Failed!");
      }
      return res.json();
    })
    .then(resData => {
      console.log(resData);
    })
    .catch(err => {
      console.log(err);
    });
const body = {
  query:
    "query {" +
    "events {" +
    "_id " +
    "num1 " +
    "num2 " +
    "addition " +
    "multiply" +
    "}}"
};
//console.log(body);
fetch("https://localhost:8000/graphql", {
  method: "POST",
  body: JSON.stringify(body),
  headers: {
    "Content-Type": "application/json"
  }
})
  .then(res => {
    if (res.status !== 200 && res.status !== 201) {
      throw new Error("Failed!");
    }
    return res.json();
  })
  .then(resData => {
    const events = resData.data.events;
    this.setState({ list: events });
  })
  .catch(err => {
    console.log(err);
  });