steamclock / netable

A Swift library for encapsulating network APIs using Codable in a type-oriented way.
MIT License
99 stars 3 forks source link

Investigate adding support for GraphQL requests #96

Closed brendanlensink closed 2 years ago

brendanlensink commented 2 years ago

This article outlines how a team built their own codebase on top of Alamofire to query GraphQL, which seems like something that would be kind of neat for Netable to support.

jenncoop commented 2 years ago

It seems worth doing a mini investigation into this to see what's involved

brendanlensink commented 2 years ago

I think this would be really useful, and potentially not super difficult given that GraphQL requests are kind of just POST requests with a weird body.

I think the biggest problem we'd want to tackle, or atleast have a good idea of what we want to do with, ahead of time is how we want to handle defining the requests. The article I originally posted sort of skips over this, as it seems like they're generating/validating their requests outside of the app. This is a pretty big part of what Apollo does, where it automatically downloads the schema from the server and does a bunch of code generation to make unwrapping things a little easier.

I sort of wonder how difficult it would be to write a wrapper that lets you skip writing the .graphql file, and instead uses the model you're expecting to be returned to generate that body automatically.

You would lose the ability to share code between other services using the same requests this way, but since you'll need to write the models anyways maybe this isn't really a big loss?