I am running a GraphQL query which returns an object. I'm certain that an object is returned but when I try to print response
on the console, I get undefined
try { const response = await loadUsers({ where: { phoneNumber: newPhoneNumber }, }); //console.log('ID', response.users.nodes[0].id); console.log('response from loadUsers is', JSON.stringify(response)); }catch (err) { console.log('err', err); } };
Previously when I was using callbacks, I did something like this and it worked:
const getFriendId = React.useCallback( (data: UsersLazyQueryHookResult) => { if (data) { if (data.users.nodes.length == 0) { Alert.alert('User Not Found'); } else { setUserData(data); console.log('ID', data.users.nodes[0].id); } } }, [addFriend], ); const [loadUsers] = useUsersLazyQuery({ onCompleted: getFriendId, onError: _onLoadUserError, });
Now, data and response are the same objects. I need to check the response.users.nodes[0].id
but I am unable to do so. Is there any other way to see the content that is being returned?
Alternatively, if instead of printing the response, I print console.log('ID', response.users.nodes[0].id)
err – TypeError: undefined is not an object (evaluating 'response.users')
I also tried using {response} instead of response but that doesn't work either. How else can I obtain the id value returned?