来自 apollo-boost 的 ApolloClient 试图分配给只读属性 [英] ApolloClient from apollo-boost attemped to assign to readonly property

查看:25
本文介绍了来自 apollo-boost 的 ApolloClient 试图分配给只读属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react-native,并尝试从 apollo-boost 加载 Apollo.当我尝试导入客户端时,收到错误消息尝试分配给只读属性".我不确定如何解决这个问题,从堆栈跟踪来看,它似乎在 apollo-boost 包中.有人知道我该如何解决这个问题吗?

I'm working with react-native, and trying to load Apollo from apollo-boost. When I attempt to import the client, I get the error message "Attempted to assign to readonly property." I'm not sure how to work around this, and it seems from the stack trace that it's in the apollo-boost package. Anybody know how I can work around this?

添加图片和细节.当我尝试通过 Expo 加载应用程序时,我得到了这个.当它开始时,我明白了.堆栈跟踪提到的我的应用程序中的第一个文件 StoresScreens,有问题的行只是导入行.

edit: Adding picture and details. I'm getting this when I try to load the app through Expo. Right when it starts, I get this. The first file in my app the stack trace mentions, StoresScreens, the line in question is only the import line.

import ApolloClient from 'apollo-boost';

推荐答案

我遇到了同样的错误.通过使用 apollo-client, apollo-cache-inmemory, apollo-link-http 包来创建 Apollo 客户端而不是使用 apollo-boost 解决.

I got the same error. Solved by using apollo-client, apollo-cache-inmemory, apollo-link-http package for creating Apollo client instead of using apollo-boost.

这是代码App.js

import React from 'react'
import ApolloClient from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';

const withProvider = (Component) => {

  const cache = new InMemoryCache();
  const link = new HttpLink({
    uri: 'your-url'
  })
  const client = new ApolloClient({
    link,
    cache
  });
  return class extends React.Component {
    render() {
      return (
        <ApolloProvider client={client}>
          <Component {...this.props} client={client} />
        </ApolloProvider>
      )
    }
  }
}
export default withProvider(App);

这篇关于来自 apollo-boost 的 ApolloClient 试图分配给只读属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆