GraphQL Initial Thoughts

 I just got my first, simple GraphQL project up and running. And, I wanted to reflect a bit on the experience and my thoughts so far.

Now, I'm starting from the assumption that one of the primary arguments in favor of GraphQL is that it loads exactly what you need, when you need it and nothing more. And that this is one of it's primary advantages over, say, OData or WebAPI.

Frankly, I think that this notion is a load of rubbish.

I see absolutely no reason why you can't do the exact same thing in OData. In fact, you can. And, if you were applying these principles rigorously there would be absolutely no need for filters or projections from the client side API.

The mere existence of filters and projections is a testament that without them, the API could/would return more or different data than you expected.

I suspect that people would argue that they are a necessary evil. That large scale development wouldn't be possible without them. And I don't disagree. Just that the second you add that caveat you've violated the principle that was supposed to make the solution superior in the first place.

And this is absolutely true of what I've seen from GraphQL. 

GraphQL is structured differently and does do some thing better than OData. It also does some things worse. I feel like GraphQL's focus (architecturally) is a huge advantage if you want that control over the results or want to get fancy in how you resolve your relationships.

It isn't that you can't do this in OData. It is just clunkier without any well established principles.

But, most of the GraphQL examples and doc and code I've seen just go and expose tables and their relationships verbatim. And this code is much more cumbersome to build with vanilla GraphQL libraries than it is in OData. 

At which point, unless there is something in particular about one framework or the other which adds a tangible benefit it seems like it would make more sense to stick with the simpler one. Which, if the focus isn't on the strengths of GraphQL and you're going to add libraries to effectively turn it into OData-lite, then I would say OData is the winner.

Now... that being said, I imagine that there is a tangible benefit: familiarity. And, I think that is a perfectly acceptable answer. My problem is that virtually no one seems willing to admit it.

Perhaps my tune will change. I'm going to stick with GraphQL for this project (it is mostly a learning exercise at this stage anyway). And I'm still a beginner by any metric on the topic. Given the size and scale of the project, I think I can get away with making the calls precisely as descriptive as they need to maximize performance. 

Comments

Popular Posts