News for hackers. Stuff that matters.
Re:Migrating Netflix to GraphQL Safely by bbbbzzz1 on Sunday June 18, 2023 @02:33PM (#36382942)
In Apollo server you can add directives to your scehma for authz. It's dead simple.

I'm surprised how so many HN posts about graphql just slander it. If you go to the website and look at the use case of why it was made, it makes it pretty clear when it could be a good to use. My experience with it has been very straight forward and a joy

Re:Migrating Netflix to GraphQL Safely by x86x87 on Sunday June 18, 2023 @02:41PM (#36383035)
I call bullshit. Where are you adding it? Api wide? Resolver? Data model? Custom?
Re:Migrating Netflix to GraphQL Safely by bbbbzzz1 on Sunday June 18, 2023 @03:37PM (#36383611)
Re:Migrating Netflix to GraphQL Safely by theturtletalks on Sunday June 18, 2023 @04:15PM (#36384003)
My SaaS backend is a GraphQL Server that has single-handedly saved me tons of hours for integrations and coding. The first iteration of the app was using rest and that was a pain. Hitting multiple endpoints to get all the details of an order is not something I miss. On top of that, I get a beautiful playground that acts as a query builder and documentation.

Have you actually used GraphQL in production or for a wide-scale project? A lot of these criticisms for GraphQL comes from people who have played with it for an hour and determined it's not good. Give it a real chance and you'll see why big companies are using it and understand why the ecosystem is growing so fast.

Re:Migrating Netflix to GraphQL Safely by x86x87 on Sunday June 18, 2023 @09:46PM (#36386410)
Yes. Used it for a a couple of large projects at BigCo. Was actually brought in to "polish" a few things. One of the original team members thought it was cool. It was a disaster. Uncovered issue after issue. Convinced management to run a bug bounty program through hackerone and I'm going to let you guess what happened.

If you're so brave and confident find a good pen tester and let them have a go at your api. It's a humbling experience.

Re:Migrating Netflix to GraphQL Safely by withinboredom on Sunday June 18, 2023 @05:41PM (#36384813)
GraphQL (as in the language spec) offers no way to perform authz. Just because there are non-standardized extensions out there for some languages, doesn't mean it is available in whatever language you're using.
Re:Migrating Netflix to GraphQL Safely by tomtheelder on Sunday June 18, 2023 @06:23PM (#36385153)
Ok, but that’s true whether or not you use GQL.
Re:Migrating Netflix to GraphQL Safely by withinboredom on Sunday June 18, 2023 @06:27PM (#36385184)
Sure. I could respond with a 4xx code because you’re not authorized for that field. Ah, but maybe you want to know which field? Too bad GQL doesn’t really support that.
Re:Migrating Netflix to GraphQL Safely by cameronh90 on Sunday June 18, 2023 @06:45PM (#36385308)
Authorization errors can go in the errors array which has a path reference in the standard.

You generally don't want to use HTTP error codes with field level errors in GQL.

Re:Migrating Netflix to GraphQL Safely by paulryanrogers on Sunday June 18, 2023 @08:47PM (#36386033)
So still a 200? Or a 202, 206, 207?
Re:Migrating Netflix to GraphQL Safely by troupo on Monday June 19, 2023 @02:44AM (#36388033)
401 or 403. Why is this a question?
Re:Migrating Netflix to GraphQL Safely by paulryanrogers on Monday June 19, 2023 @10:00AM (#36391186)
Because there may be fields requested correctly alongside some requested incorrectly
Re:Migrating Netflix to GraphQL Safely by troupo on Monday June 19, 2023 @02:14PM (#36394610)
Outside of very few cases it means the request was incorrect.

And bo one is stopping you from returning a response that contains error details.

Re:Migrating Netflix to GraphQL Safely by satvikpendem on Sunday June 18, 2023 @07:45PM (#36385698)
GraphQL has strongly typed errors unlike REST. It is very akin to the Result type in many languages in that you are forced to handle errors even when writing the query, and the query will simply not compile if you don't.

For example, the Pothos library implements this pattern automatically:

    type Error {
      message: String!
    }
    
    type Query {
      hello(name: String!): QueryHelloResult
    }
    
    union QueryHelloResult = Error | QueryHelloSuccess
    
    type QueryHelloSuccess {
      data: String!
    }
    
This field can be queried using fragments like:

    query {
      hello(name: "World") {
        __typename
        ... on Error {
          message
        }
        ... on QueryHelloSuccess {
          data
        }
      }
    } 

https://pothos-graphql.dev/docs/plugins/errors
Re:Migrating Netflix to GraphQL Safely by withinboredom on Monday June 19, 2023 @01:39AM (#36387673)
But now I’m most likely returning a 2xx response. There are asshole corporate middle boxes somewhere that will cache it. If I return a 4xx response, from experience (albeit nearly 5 years ago) I’ll crash your client. Now what?

If someone has solved the asshole corporate middle box problem using GQL, that’s really good news.

Re:Migrating Netflix to GraphQL Safely by sodapopcan on Sunday June 18, 2023 @07:53PM (#36385740)
For me it was the prevalence of GraphQL that was annoying. I have worked with it and liked it as a technology, but it was a tell from the org I worked for an was definitely overkill for what we were doing. No matter how you slice it, GraphQL is added complexity compared to REST but of course, as with a lot in our industry, there are all the people bought in who put in the time to learn it who are going to shout, "Naw, it's easy!" To be clear I'm not saying GraphQL is super complex, just more complex than REST and if all you need is REST then that is what you should be using. Yet in my many interviews over the past year I talked to a bunch of companies who used GraphQL and I'd say, "Oh, cool, why did you choose it?" and they'd say something along the lines of, "Well, the CTO who wrote the original app thought it was cool at the time." So I've always got the impression that the backlash mostly comes from the huge evangelism it got making it out to be The New Way. Again, to be clear, I'm not saying it was marketed this way but it's how it felt at the time. Annnd again, I know this happens constantly in our field.