News for hackers. Stuff that matters.
Re:REST vs. GraphQL – A search for evidence on which is better by gabereiser on Tuesday December 15, 2020 @11:36PM (#25439111)
Same. This is why I was looking for concrete examples because the problem isn’t a graphql problem, it exists in any interface. Kinda a trick question, but it was good reading people’s reasoning ;)
Re:REST vs. GraphQL – A search for evidence on which is better by baumandm on Wednesday December 16, 2020 @02:03AM (#25439871)
I agree with GP as well, but I do think there are unique circumstances with GraphQL.

One difference is that if the front-end makes N+1 REST calls, it's (hopefully) obvious to the front-end developer. It's also generally easy to map the REST requests to the database queries being made.

Swap it all out for a single GraphQL query and now you have no idea how it will perform or whether it was optimized for the specific fields you are requesting.

Another difference is that REST-style solutions won't work for GraphQL. Imagine you're making a bunch of REST calls, e.g. querying for a list of articles then querying for a list of comments for each one. You can ask the backend team for a new endpoint that returns them all in one query, easy enough.

But with GraphQL schemas, the potential graph of data is too large to write custom SQL queries that efficiently fetch everything in one batch. For example:

  {
    articles {
      title
      contents
      author {
        name
        articles {
          title
          contents
          comments {
            content
            author {
              ...
            }
          }
        }
      }
      comments {
        content
        author {
          name
        }
      }
    }
  }
Maybe a bit contrived, but it illustrates my point. Due to the ability to traverse relationships it's much easier to find yourself in a situation where the implementation of the GraphQL resolvers is not ideal for the usage, but it theoretically will work.
Re:REST vs. GraphQL – A search for evidence on which is better by valenterry on Wednesday December 16, 2020 @02:27AM (#25439976)
The GraphQL equivalent to creating a new, specialized REST route would be to create a new, specialized query.

E.g. the following REST

    /articles-with-comments?number=20
which returns title, contents etc. would map to a completely new query in graphql

    articlesWithComments(number: Integer) {
      title
      contents
      ...
    }
so it is exactly as easy to optimize. Of course this is not very composable, but that is equally true for both solutions.
Re:REST vs. GraphQL – A search for evidence on which is better by gabereiser on Wednesday December 16, 2020 @12:55PM (#25445783)
and this is the pattern we see in the wild mostly.
Re:REST vs. GraphQL – A search for evidence on which is better by Aeolun on Wednesday December 16, 2020 @07:30AM (#25441772)
Apparently you could solve this using the dataloader pattern/library.

Every layer would send off one query, unless they’re dependent on each other, but it’d be a far cry from N+1