问题
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