reactjs - TypeError: possibleTypes[supertype].forEach 不是函数
问题描述
这是我的代码。
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
import { createHttpLink } from "apollo-link-http";
import { render } from "react-dom";
import React from "react";
import RouteCollector from "./routeCollector";
import "./index.css";
import possibleTypes from "./tools/graphqlCodeGenerator/possibleTypes.json";
const cache = new InMemoryCache({
possibleTypes,
});
const link = createHttpLink({
uri: "http://localhost:8000/graphql",
credentials: "include",
});
const client = new ApolloClient({
cache,
link,
});
render(
<ApolloProvider client={client}>
<RouteCollector />
</ApolloProvider>,
document.getElementById("root")
);
我正在使用 包" @ apollo / client ":" ^ 3.0.2 "
,,,"apollo-link-http": "^1.5.17",
"graphql": "^15.3.0"
"react": "^16.13.1",
当我运行程序时出现错误
TypeError: possibleTypes[supertype].forEach 不是函数
如何修复错误?
解决方案
如果您使用的是 GraphQL 代码生成器,则应确保使用插件possibleTypes
生成的对象的属性fragment-matcher
,如下所示:
import introspectionResult from '../introspection-result';
const cache = new InMemoryCache({
possibleTypes: introspectionResult.possibleTypes,
});
您不能传递生成的整个对象。
您还需要确保在 codegen 配置中设置apolloClientVersion
为以确保生成正确的对象。3
推荐阅读
- excel - 如何检查单元格是否包含多个值之一,如果这些列都包含任一值,则如何更改另一个单元格
- html - 在同一段落中为罗马和斜体文本使用不同大小的字体
- ios - 在用户的文档文件夹中创建一个新的子文件夹会创建一个文件
- node.js - Discord Music 机器人随机抛出此错误,显然没有挑衅
- python - 递归生成器说明
- reactjs - 如何部署具有代码拆分功能的 JS 应用程序,确保过去的应用程序版本不会中断
- svelte - Storybook 不会加载简单的组件
- r - 用保存在R中其他变量中的字符串重命名变量
- xcode - Xcode 错误。无法使用从我的 Git 代表克隆的 Mapbox API 构建 iOS 应用程序
- python - PyQt5 QTableWidget插入熊猫头数据