Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

check shape of object returned by grapqhl query

$
0
0

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].idbut 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?


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>