Solved

Why does GraphQL work the way it does?

DazC
Excursionist
17 0 15

Perhaps far too broad a question for the forums, but I’ve just completed some work on an automation that edits Shopify orders to add a free gift post sale, and I’m a bit confused.

 

 First off, the REST API doesn’t have a facility to edit orders as far as I can tell, at least not in a meaningful way where you can change line items. You can update tags, change statuses, but not much else.  The GraphQL API, however, does (why can’t the REST API do this?)

 

Following the example guide for editing a product, I ended up having to create 4 sequential tasks just to add a single line item to an order. You have to initialise the order for editing, then add a line item, then add a discount to that line item, and finally commit the changes. Why can’t I do this in a single POST request, or less of them at least? Why can’tI add a line item with a discount at the same time?

 


I’m very new to GraphQL so I presume there must be a benefit to this stateful behaviour, and also a reason why the more simplistic REST API doesn’t allow you to edit orders. Perhaps I’m simply using it wrong, but the system I was using (Zapier) treated each part of the process as a web request (and billed me accordingly)

 

Interested to hear thoughts. 🙂 Thanks in advance.

Accepted Solution (1)

PaulNewton
Shopify Partner
6275 573 1323

This is an accepted solution.

Yes you're asking a vague broad surface questions about fundamental web technology architectures and how platforms structure apis.

Whose vague unsatisfying surface answer is because those resources are different resources your interacting with through a machine over a network and just because there are abstractions doesn't mean there can be conveniences treating them as a single resource; which generally doesn't make sense until you yourself try to build such a system and have to be responsible for it's operating costs.

i.e. an order has line items an order is NOT just line items, a line has discounts a line is NOT discounts.

 

https://www.google.com/search?q=rest+vs+graphiql 

https://shopify.engineering/understanding-graphql-beginner-part-one 

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


View solution in original post

Replies 2 (2)

PaulNewton
Shopify Partner
6275 573 1323

This is an accepted solution.

Yes you're asking a vague broad surface questions about fundamental web technology architectures and how platforms structure apis.

Whose vague unsatisfying surface answer is because those resources are different resources your interacting with through a machine over a network and just because there are abstractions doesn't mean there can be conveniences treating them as a single resource; which generally doesn't make sense until you yourself try to build such a system and have to be responsible for it's operating costs.

i.e. an order has line items an order is NOT just line items, a line has discounts a line is NOT discounts.

 

https://www.google.com/search?q=rest+vs+graphiql 

https://shopify.engineering/understanding-graphql-beginner-part-one 

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


DazC
Excursionist
17 0 15

Thanks. I probably should’ve spent at least some time looking into the differences myself, but I’d just come off a long day trying to brute force a solution to something without the benefit of being able to learn the differences at a calmer pace.

 

I appreciate the resources, will do some reading up. 🙂