Müşteri.fetchPolicy "bekleme" olarak ayarlandığında watchQuery çağrılamaz-uselazyquery'den sayfa yüklenirken hata oluştu

0

Soru

Tsx ile yazılmış bir sayfam var, bu da hatayla birlikte yüklenirken çökmeye devam ediyor client.watchQuery cannot be called with fetchPolicy set to "standby" söz konusu sorgu useLazyQuery olsa da (bu yüzden henüz çalışmadı) ve seçeneği var fetchPolicy: 'no-cache'. Benim için çöküyor, ancak takım arkadaşlarım için değil, bu da belki yerel typescript'imin paket sürümleriyle bir ilgisi olabileceğini düşündürüyor, ancak bunu herhangi bir gelişme olmadan düşünebildiğim her şekilde ayarladım ve yeniden ayarladım. İlgili kod ve paket.json'lar aşağıda. Herhangi bir içgörü harika olurdu.

// 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"
  },
3
1

Benzer bir sorun yaşıyordum. useQuery, 3.5'te defaultOptions kullanmıyor gibi görünüyor @apollo/client (bir bağımlılık @apollo/react-hooks).

Benim için çözüm, ayarlayarak düşürmekti "@apollo/client": "~3.4.0" in the package.json ve koş npm install. Seninkini kontrol et package-lock.json değiştirdiğinizden emin olmak için 3.5.x sürüm.

2021-11-25 03:34:03
1

@apollo/react-hooks bir bağımlılığı vardır @apollo-client.

İçe aktardıysanız useQuery -den @apollo/react-hooks, o zaman içe aktarmanız gerekir useQuery/useLazyQuery -den @apollo-client yerine @apollo/react-hooks 3.5'in altındaki sürümle birlikte.

2021-11-29 19:47:41
1

Kullanmakta olan mevcut bir react uygulamasıyla yapılan bir yapıdaki bu hata için interneti taradım nwb sonunda buna rastlamadan önce. Benim durumumda, apollo client sürüm 3.0.2 idi. Paketimi güncelliyorum.jsonname "@apollo/client": "~3.4.0" ve yeniden koşuyor npm i sonunda numarayı yaptım. Teşekkürler @ GratefulGuest!

2021-11-29 18:26:57

Diğer dillerde

Bu sayfa diğer dillerde

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................