artsy / artsy.github.io

The Artsy Engineering Open-Source Developers Blog
https://artsy.github.io
MIT License
1.09k stars 227 forks source link

Comments: Is GraphQL The Future? #443

Open acjay opened 6 years ago

acjay commented 6 years ago

I have seen the future, and it looks a lot like GraphQL. Mark my words: in 5 years, newly minted full-stack app developers won’t be debating RESTfulness anymore, because REST API design will be obsolete. By the end of this post, I hope you'll see what I see in the promise of GraphQL as a new approach to client-server interaction.

itaditya commented 6 years ago
@acjay great article, ...[edit by orta] however there is one mistake in it. The article is giving the impression that rest is nothing but a network request. > Rest for static assets is good, but have problem with API The static assets has nothing to do with REST. It's a function of HTTP. Please correct it. Also I would like to know the pain points you're having with REST.
orta commented 6 years ago

Hi @itaditya - this comment doesn't really add much to the conversation, I'm quite picky about keeping our blog comments positive, constructive and on-topic. So, I'm going to have it hidden by default. You're welcome to edit it and improve it to add to the discussion 👍

brucou commented 6 years ago

Pretty interesting article, which generated a few comments that I submit to your consideration:

acjay commented 6 years ago

@itaditya -- your post came off to us a demanding changes, but presuming that wasn't how you intended it to be received, I want to address a couple of your points.

The static assets has nothing to do with REST. It's a function of HTTP.

I mean specifically that I think REST--as the primary design principle for accessing and managing data via HTTP--makes a lot of sense to me as a way of managing concrete resources, like static assets. It's clearly way more general than that. I'm saying that it's a great fit for documents and assets. Probably because those don't require a great deal of the subtlety of REST in its full glory.

Also I would like to know the pain points you're having with REST.

Here are some pain points with REST, in my personal experience/observation:

I'm not saying these are universal drawbacks, felt equally by everyone. I'm just saying I think we can do better. A better system would allow a developer to more directly work with their domain concepts and their most unique tech concerns, and spend less time on the banal parts of the machinary. Obviously, I see GraphQL as a big step in that direction.

acjay commented 6 years ago

@brucou Thanks for the thoughts and questions!

it seems however that that language have no proper lambda abstraction

Funny thing about this is in the course of some exploratory work on live queries, I've done some thinking about how you might get around this limitation. I no longer think this is the way to go, but it's interesting that there are ways you could immitate closures.

I was however lost in the mutation part [...]

What I mean here is that mutations in GraphQL have a return type. The most obvious return type you could chose is something that represents the result of the mutation. But that's not the only option. Your schema can specify anything you want as the return type, which could encompass the specific data changed by the mutation and/or anything else. This allows you the option to permit arbitrary follow-up queries. But this is up to you and how you want to allow your API to be used, which you determine through your schema design. In REST, follow-up operations are entirely separate requests. In my experience, this is often very tedious to orchestrate on the client-side.

In the GraphQL spec, the only fields that are mutations are the fields of the root type of the mutation operation. The root mutation fields definitely execute in series, much like in a typical programming language. If those fields return object types, the subfields are considered queries and execute in nondeterministic order. I happen to think it would have been interesting to have not made this distinction, because GraphQL already supports sequential execution, via nesting 😄.

hpatoio commented 6 years ago

@acjay

Here are some pain points with REST, in my personal experience/observation:

Endless design bikeshedding seeking RESTfulness. Perpetually poor API documentation. Inconsistency of conventions between server frameworks. Inconsistency of conceptual approaches between projects. Tends to push a lot of complexity to API clients.

I don't see how these issues are "fixed" in GraphQL. Last one in particular. I think that GraphQL push even more complexity to the client.

You also forget to talk about hypermedia. I very powerful "feature" of REST API.

wxia20 commented 5 years ago

Great writing on GraphQL I have ever read, very well explained!

fullStackDataSolutions commented 5 years ago

Great article. One of my favorite parts of GraphQL is that you can introspect and get the Schema in your app. This allows me to automate form creation for mutations, and to recursively traverse the schema to generate mutations and queries. If someone changes something on the back end the front end is updated just by doing an introspection, no need to write new front end code.

Because the data in GraphQL is uniform in the way it comes from in from quires, there are many things that can automated on the front end, which are not possible with REST. Such creating tables from edges and nodes.

GraphQL also greatly reduces the work the back end team needs to do to build and maintain the API. They don't need to worry about adding new routes every time the front end team needs new data, they can just expose it all in types, and if a new type is needed then expose that.

It is a very powerful tech if properly leveraged, and once developers realize what can be done with it, they will be clamoring to use it.

leoloso commented 4 years ago

@acjay This article is a terrific read, thanks for writing it!

Concerning GraphQL being a (meta-)scripting language, that currently doesn't completely ring true to me, because it's hidden, very hidden from the front-end developer who will code the query to access the data. Even if it uses looping/variables in its implementation in the back-end, if not directly available to the client-side, then it can't really be called a (meta-)scripting language.

Concerning this topic, I am actually working on extending GraphQL to make it apparent it is a scripting language, by giving access to programming features through the query itself, including:

This work is in its early days, but it can already satisfy very complex queries (btw, the demonstrated final query might struck you in how explicit the control flow is).

So I do agree that the future looks like GraphQL, but I'm also certain that it will not be GraphQL, because GraphQL is actually still very limited, and so much more is possible (as I'm attempting to demonstrate). Yes, a step forward from REST, but far away from its final potential.

Btw, it's been more than 1.5 years since you wrote this article. I wonder what new insights you got since then? A follow up to this article would be wonderful 😀

ashfurrow commented 4 years ago

@leoloso that's really cool! Alan has moved on from Artsy, so I wanted to drop in and point to our more recent GraphQL blog posts, and I think this one about using custom directives might be of particular interest to you: https://artsy.github.io/blog/2020/01/13/graphql-custom-directives/

Take care!