apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.88k stars 728 forks source link

Painfully complex #2844

Closed mikemilla closed 1 year ago

mikemilla commented 1 year ago

Use case

Simply using a string as the query doesn't work. Why do I need a cli, fully schema, and generated types when I should just be able to pass a string as the query?

Describe the solution you'd like

Allow passing a string as the query, allow using JSON.decode() as the result parsing. Ya know, like URL session.

Having a simple way to add headers would be nice too rather than writing an obnoxious interceptor.

I don't want to think, I just want this to work with headers and normal swift convention.

sgade commented 1 year ago

Type-safe API interactions using a schema is the key idea behind GraphQL. Apollo implements that and provides additional features like a cache. I suggest reading the introductory paragraphs.

If you want to do requests and response parsing by hand without type-safety, you're always able to send requests using URLSession directly.

calvincestari commented 1 year ago

Hi @mikemilla. You're asking for a completely different type of client, essentially one which was designed with a different philosophy in mind.

Apollo iOS is designed to return your responses as type-safe Swift. To do that we need to have Swift models that match the shape of your GraphQL operations. You could hand-write these but I wouldn't advise it and it's going to be tedious, which is why we offer code generation. To do code generation we need the schema, operations and then a configuration for you to tailor the output. We offer tools like the CLI to make this easier than having to use ApolloCodegenLib in code.

@sgade is correct - you have all the tools available right now from Apple in their frameworks if you want to build a more dynamic GraphQL client. I believe there is a huge amount of value in Apollo iOS and its design as a GraphQL client; GraphQL and Apollo iOS both have steep learning curves though. We are always improving the library and our documentation but we're always open to PRs and docs improvements.