首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在fetchPolicy设置为"standby“的情况下调用client.watchQuery --从useLazyQuery加载页面时引发错误

无法在fetchPolicy设置为"standby“的情况下调用client.watchQuery --从useLazyQuery加载页面时引发错误
EN

Stack Overflow用户
提问于 2021-11-23 23:56:25
回答 3查看 1.3K关注 0票数 4

我有一个用tsx编写的页面,即使查询是useLazyQuery (所以它还没有运行),它仍然在加载时崩溃,错误为client.watchQuery cannot be called with fetchPolicy set to "standby",并且有fetchPolicy: 'no-cache'选项。它对我来说崩溃了,但对我的队友来说不是,这让我认为它可能与我的本地typescript的软件包版本有关,但我已经用我能想到的每一种方法对它进行了设置和重新设置,没有任何改进。相关代码和package.json如下。任何洞察力都会很棒。

代码语言:javascript
复制
// myfile.tsx
const [getRoles] = useLazyQuery(GET_ALL_ACCOUNT_ROLES, {
    fetchPolicy: 'no-cache',
    onError: (e) => {
      console.error(e.message);
      showPrompt({ type: 'error', message: 400 });
    },
    onCompleted: async (data) => {
      const {
        getAllAccountRoles: { data: res }
      } = data;
      setAllRoles(res);
    }
  });
代码语言:javascript
复制
package.json
"dependencies": {
    "@apollo/react-hooks": "^4.0.0",
    "@aws-amplify/api": "^4.0.13",
    "@aws-amplify/auth": "^4.1.3",
    "@emotion/react": "^11.4.1",
    "@emotion/styled": "^11.3.0",
    "@loadable/component": "^5.15.0",
    "@mui/icons-material": "^5.1.0",
    "@mui/material": "^5.1.0",
    "@mui/system": "^5.1.0",
    "@reach/router": "^1.3.4",
    "@rinxun/custom-questions": "^1.1.2",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "apollo-boost": "^0.4.9",
    "apollo-cache-inmemory": "^1.6.6",
    "apollo-client": "^2.6.10",
    "apollo-link": "^1.2.14",
    "apollo-link-context": "^1.0.20",
    "apollo-link-http": "^1.5.17",
    "aws-appsync-auth-link": "^3.0.6",
    "check-equal": "^1.0.7",
    "clsx": "^1.1.1",
    "dotenv": "^10.0.0",
    "env-cmd": "^10.1.0",
    "mockjs": "^1.1.0",
    "qrcode.react": "^1.0.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-dropzone": "^11.3.4",
    "react-scripts": "4.0.3",
    "store": "^2.0.12",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@storybook/addon-actions": "^6.3.2",
    "@storybook/addon-essentials": "^6.3.2",
    "@storybook/addon-links": "^6.3.2",
    "@storybook/node-logger": "^6.3.2",
    "@storybook/preset-create-react-app": "^3.1.7",
    "@storybook/react": "^6.3.2",
    "@types/aws4": "^1.5.2",
    "@types/jest": "^26.0.24",
    "@types/loadable__component": "^5.13.4",
    "@types/qrcode.react": "^1.0.2",
    "@types/react": "^17.0.15",
    "@types/react-dom": "^17.0.9",
    "@types/uuid": "^8.3.1",
    "@typescript-eslint/eslint-plugin": "^4.29.1",
    "@typescript-eslint/parser": "^4.29.1",
    "aws4": "^1.11.0",
    "babel-eslint": "^10.1.0",
    "babel-loader": "8.1.0",
    "eslint": "^7.32.0",
    "eslint-config-react-app": "^6.0.0",
    "eslint-plugin-flowtype": "^5.9.0",
    "eslint-plugin-import": "^2.24.0",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-react": "^7.24.0",
    "eslint-plugin-react-hooks": "^4.2.0",
    "graphql": "^15.5.1",
    "lint-staged": "^11.1.1",
    "prettier": "2.3.2",
    "typescript": "^4.3.5",
    "web-vitals": "^1.0.1"
  },
EN

回答 3

Stack Overflow用户

发布于 2021-11-25 03:34:03

我也遇到了类似的问题。追溯到@apollo/client中的问题useQuery doesn't seem to use defaultOptions in 3.5 (@apollo/react-hooks的依赖项)。

对我来说,解决方案是通过在package.json中设置"@apollo/client": "~3.4.0"并运行npm install来降级。检查你的package-lock.json,确保你已经更换了你的3.5.x版本。

票数 3
EN

Stack Overflow用户

发布于 2021-11-29 18:26:57

@apollo/react-hooks具有@apollo-client的依赖项。

如果您已经从@apollo/react-hooks导入了useQuery,那么您需要从@apollo-client导入useQuery/useLazyQuery,而不是@apollo/react-hooks,以及低于3.5的版本。

票数 1
EN

Stack Overflow用户

发布于 2021-12-15 20:05:34

我在互联网上搜索了一个使用nwb的现有react应用程序,在最终偶然发现这个错误之前,我搜索了一下这个错误。在我的例子中,apollo client版本是3.0.2。更新我的package.json "@apollo/client": "~3.4.0"并重新运行npm i终于成功了。感谢@GratefulGuest!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70089245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档