Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

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

Andreas_Sch
Excursionist
18 0 5

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

Replies 2 (2)

Gregarican
Shopify Partner
1033 86 292

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
18 0 5

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!