General GraphQL response parse question: Just using Dicts or Objects?

Andreas_Sch
Excursionist
17 0 0

Hello,

I am aware this could be topic of controversial points of view, but I am really interested in others opinion.

Using GraphQL for some time I find it tiresome to access response data manually like:

 

 

has_next_product_variants_page = response['data']['product']['variants']['pageInfo']

 

 

 

It's highly repetitive and error prone.

 

For Python there is the Simple GraphQL Client, which can create code to convert the JSON query to result objects which one can access like:

 

 

has_next_product_variants_page = response.data.product.variants.pageInfo

 

Here the IDE and type checking can help you identifying errors. On the minuses side one wold have to generate the code for every query, otherwise you would loose the benefits of just retrieving the information you need and not the whole object (eg. Product, Collection). This would be a downgrade to GraphQL fetched REST.

Has anybody experience with libraries like this?
What are your thoughts?

Best,
Andreas

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

Assuming you are using Python for development, have you looked into this? http://objectpath.org/ 

Should make is easier to drill into a nested JSON response and pull just what you need. 

Andreas_Sch
Excursionist
17 0 0

As GraphQL offers a schema, it's still a lot of manual labor to drill into the results.

I decided to give sqlc a shot and we'll see. First impression was good today...

But objectpath for sure will come in handy one day
Thanks for the tip!

0 Likes