TypeError: possibleTypes[supertype].forEach is not a function
TypeError: possibleTypes[supertype].forEach is not a function
这是我的代码。
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 is not a function
如何修复错误?
如果您使用的是 GraphQL 代码生成器,则应确保您使用的是 fragment-matcher
插件生成的对象的 possibleTypes
属性,如下所示:
import introspectionResult from '../introspection-result';
const cache = new InMemoryCache({
possibleTypes: introspectionResult.possibleTypes,
});
您不能传递生成的整个对象。
您还需要确保在代码生成配置中将 apolloClientVersion
设置为 3
,以确保生成正确的对象。
这是我的代码。
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 is not a function
如何修复错误?
如果您使用的是 GraphQL 代码生成器,则应确保您使用的是 fragment-matcher
插件生成的对象的 possibleTypes
属性,如下所示:
import introspectionResult from '../introspection-result';
const cache = new InMemoryCache({
possibleTypes: introspectionResult.possibleTypes,
});
您不能传递生成的整个对象。
您还需要确保在代码生成配置中将 apolloClientVersion
设置为 3
,以确保生成正确的对象。