Hacker News new | ask | show | jobs
by tony 2441 days ago
Starred.

Aside: If this is appealing to you (automated typing in REST) I think you would love GraphQL.

Typing is baked into graphql (https://graphql.org/learn/schema/#type-system). You can do it with graphene (https://graphene-python.org/) and django's graphene-djanago (https://github.com/graphql-python/graphene-django) which handles ORM wrapping and a view baseclass.

Having experience with it, one major downside is how exception handling works in graphene. There is a strange implementation of promises which doesn't translate well into python IMO. It ends up hijacking error resolution, making it hard to control execution.

On the other hand, being able to get instant documentation from graphql is a big benefit. Everything generates nicely to a schema.graphql file.

Instead of POST and PUT, graphql has a concept of mutations: https://graphql.org/learn/queries/, GET would be a query.

Also, graphql has built-in pagination via Connections: https://graphql.org/learn/pagination/

I still use REST in many places, but graphql has been one thing where the learning curve paid off. I wish REST had typing baked into it from the beginning.

1 comments

I've followed GraphQL from a distance. Besides the typing part (which it seems like you can get from OpenAPI to some extent), the other big benefit seems to be being able to cater to many different and unpredictable use cases. But I haven't really had a need for that yet.