TypeError - undefined is not an object (evaluating 'c.currentObservable.query.refetch'). in react native

Viewed 1151

My codes works well but after fast refersh and do refresh with refreshControl i got this error in React Native

TypeError - undefined is not an object (evaluating 'c.currentObservable.query.refetch').

Check error Image here

This is my code

const getTopics = useQuery(getAllTopicsSchema);
const [refreshing, setRefreshing] = React.useState<boolean>(false);
 <ScrollView
            refreshControl={
                <RefreshControl
                    refreshing={refreshing}
                    onRefresh={() => {
                        setRefreshing(true);
                        getTopics.refetch().then((res: any) => { setRefreshing(false)).finally(() => setRefreshing(false));
                    }} />
            }>
               {
                getTopics.data && getTopics.data.findAllTopic.map((res: Topic) => <View><Text>{JSON.stringify(res)}</Text></View>)
                }
</ScrollView>
1 Answers

I'm not sure if this will help or if your problem is different, but I have found this reddit post while I was having a similar problem and it fixed for me, so I'm adding it here for people in the future or with similar problems with react native and apollo.

You need to check your ApolloClient config, as the comment says:

the uri can't be localhost and instead has to be your device's local ip address. Took me hours to figure this out.

For example, if your config is something like

const client = new ApolloClient({
  ...configRest,
  uri: 'http://localhost:4000/graphql'
})

You would need to change it to

const client = new ApolloClient({
  ...configRest,
  uri: 'http://YOUR_IP_ADDRESS:4000/graphql'
})
Related