这是我的密码。
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: possibleTypessupertype.forEach不是一个函数
如何修正错误?
发布于 2020-07-27 19:15:18
如果使用的是GraphQL代码生成器,则应确保使用由fragment-matcher插件生成的对象的possibleTypes属性,如下所示:
import introspectionResult from '../introspection-result';
const cache = new InMemoryCache({
possibleTypes: introspectionResult.possibleTypes,
});不能传递生成的整个对象。
您还需要确保在codegen配置中将apolloClientVersion设置为3,以确保生成正确的对象。
https://stackoverflow.com/questions/63120902
复制相似问题