首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError: possibleTypes[supertype].forEach不是函数

TypeError: possibleTypes[supertype].forEach不是函数
EN

Stack Overflow用户
提问于 2020-07-27 17:56:55
回答 1查看 376关注 0票数 1

这是我的密码。

代码语言:javascript
复制
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不是一个函数

如何修正错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-27 19:15:18

如果使用的是GraphQL代码生成器,则应确保使用由fragment-matcher插件生成的对象的possibleTypes属性,如下所示:

代码语言:javascript
复制
import introspectionResult from '../introspection-result';

const cache = new InMemoryCache({
  possibleTypes: introspectionResult.possibleTypes,
});

不能传递生成的整个对象。

您还需要确保在codegen配置中将apolloClientVersion设置为3,以确保生成正确的对象。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63120902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档