Home > other >  ReactNative Expo Go useQuery @apollo/client hook doesn't run on IOS phone but useLazyQuery does
ReactNative Expo Go useQuery @apollo/client hook doesn't run on IOS phone but useLazyQuery does

Time:05-12

Hello I am currently running an ApolloServer with Ngrok. Everything works fine on the web, but on my IOS phone I'm using with ExpoGo my graphql refuses to return data.

Using mutations is fine and works perfectly. All the queries work in the sandbox.

If I use the useQuery hook the ApolloServer doesn't even receive the query(I have a console.log in the resolver). If I use the useLazyQuery the server receives the request, the result in the resolver is correct, but my IOS phone doesn't seem to get it. Nothing reloads.

I have no idea where else to go from here.

//Basically 
import { useQuery } from '@apollo/client';

const [taskData, setTaskData ] = React.useState([]);

 const { loading, error, data } = useQuery(GET_TASKS, {
        onCompleted: (data) => setTaskData(data["getTasksById"]),
        variables: { userId: 1 }
    })

return (
        <View style={{ marginBottom: useBottomTabBarHeight()   45 }}>
            <FlatList
                data={getFilterData()} //function where i filter items
                renderItem={({ item }) => <Task id={item.id} content={item.content} finished={item.finished} updateFinishedStatus={handlePress} />}
            />
        </View>
    )}
export const GET_TASKS = gql`
query GetTasksById($userId: ID) {
  getTasksById(id: $userId) {
    id
    content
  }
}`

and the client

    const apolloClient = new ApolloClient({
    cache: new InMemoryCache(),
    link: ApolloLink.from([errorLink, httpLink])
});

CodePudding user response:

I had the exact same problem. I managed to solve it by using older versions of Apollo Client and Graphql as suggested here: 'loading' remains true when loading data with 'useQuery' using 'apolloClient' in react-native

  • Related