Back

[SOLVED] Retrieve promise object data from graphql query

  • 0
  • Databases
  • Web
Drake
3 Mar, 2023, 03:45

The documentation I linked was info on fetch and promises. Query is not fetch, so it doesn't return the same thing and you won't get Received response: 200

TL;DR
The user was having trouble accessing attributes under the "documents" data in a GraphQL query. They tried using console.log but couldn't figure out how to access the desired value. They also asked for help in finding the proper response code. Another user suggested logging the response to understand how to use it. The user mentioned they were getting an "undefined" response. The final response mentioned that the documentation the user previously linked was about fetch and promises, not the GraphQL query they were using.
truth
3 Mar, 2023, 03:46

I understand.

truth
3 Mar, 2023, 03:46

I was getting an "undefined" response. How do i resolve that?

Drake
3 Mar, 2023, 03:46

Log response to see if that will help you figure out how to use it

truth
3 Mar, 2023, 03:47

it hasn't helped

Drake
3 Mar, 2023, 03:47

What is your code now? With logging response?

truth
3 Mar, 2023, 03:50
Drake
3 Mar, 2023, 03:51

You should know how to work with response now

truth
3 Mar, 2023, 03:56

well I didn't get any data in that response which I should have, but I can't get that json again. I'm only getting the red error in the photo

Drake
3 Mar, 2023, 03:56

You're getting that error because there's something wrong with your code

truth
3 Mar, 2023, 05:52

Please tell me how I could find out the proper response code since the following is incorrect:

TypeScript
     if (!response.ok) {
     }
Drake
3 Mar, 2023, 05:52

Response doesn't have an ok property. Look at what was logged

truth
3 Mar, 2023, 05:53
truth
3 Mar, 2023, 05:54

This is actually a desired object, rather than a bad response... but I don't have the conditional correct

Drake
3 Mar, 2023, 05:55
truth
3 Mar, 2023, 05:56

yes. I did see that sometimes an error array will exist when I forced an error

truth
3 Mar, 2023, 06:16

I'm able to get information up to console.log(response.data.search1.documents[0].data); but I can't access the attributes under the documents data. For example I want to access group_a value of "bye" I will try mapping

truth
3 Mar, 2023, 06:16
Drake
3 Mar, 2023, 06:20

Can you tell what the type is for the value of the document data?

truth
3 Mar, 2023, 06:21

string

truth
3 Mar, 2023, 06:23

maybe I need to convert it

truth
3 Mar, 2023, 06:27

EUREKA!

truth
3 Mar, 2023, 06:29

THANK you for walking with me on this journey πŸ˜„

Drake
3 Mar, 2023, 06:32

[SOLVED] Retrieve promise object data from graphql query

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more