client.watchQuery 无法在 fetchPolicy 设置为“standby"的情况下调用;-- 从 useLazyQuery 加载页面时抛出的错误 [英] client.watchQuery cannot be called with fetchPolicy set to "standby" -- Error thrown on page load from useLazyQuery

查看:31
本文介绍了client.watchQuery 无法在 fetchPolicy 设置为“standby"的情况下调用;-- 从 useLazyQuery 加载页面时抛出的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 tsx 编写的页面,它在加载时不断崩溃并出现错误 client.watchQuery cannot be called with fetchPolicy set to standby",即使有问题的查询是 useLazyQuery(所以它尚未运行),并且具有选项 fetchPolicy: 'no-cache'.它对我来说崩溃了,但对我的队友却没有,这让我认为这可能与我本地打字稿的包版本有关,但我已经设置并重新设置了我能想到的所有方式,但没有任何改进.相关代码和 package.json 如下.任何见解都会很棒.

I have a page written in tsx that keeps crashing on load with the error client.watchQuery cannot be called with fetchPolicy set to "standby", even though the query in question is useLazyQuery (so it hasn't run yet), and has the option fetchPolicy: 'no-cache'. It crashes for me, but not for my teammates, which makes me think it might have something to do with package versions of maybe my local typescript, but I've set and re-set it every way I can think of with no improvement. The relevant code and package.json are below. Any insight at all would be wonderful.

// 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);
    }
  });

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"
  },

推荐答案

我在使用 nwb 的现有 React 应用程序构建时,在互联网上搜索了这个错误,最后才发现这个错误.就我而言,apollo client 版本是 3.0.2.更新我的 package.json "@apollo/client": "~3.4.0" 并重新运行 npm i 终于成功了.谢谢@GratefulGuest!

I scoured the internet for this error on a build with an existing react app that was using nwb before finally stumbling upon this. In my case, the apollo client version was 3.0.2. Updating my package.json "@apollo/client": "~3.4.0" and re running npm i finally did the trick. Thank you @GratefulGuest!

这篇关于client.watchQuery 无法在 fetchPolicy 设置为“standby"的情况下调用;-- 从 useLazyQuery 加载页面时抛出的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆