ApolloClient from apollo-boost attemped to assign to readonly property

六眼飞鱼酱① 提交于 2021-02-10 03:09:00

问题


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?

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';

回答1:


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.

Here's the code 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);



回答2:


At least using Typescript, as temporary workaround you can do:

import ApolloClient from "apollo-boost/lib/index";

Seems related with this issue: https://github.com/apollographql/apollo-client/issues/4843



来源:https://stackoverflow.com/questions/56263102/apolloclient-from-apollo-boost-attemped-to-assign-to-readonly-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!