Comments (5)
Although it is private and not well documented, it seems you should be able to use _ObjectiveCBridgeable
to bridge Swift structs and Objective-C classes even in the current Swift version (see this post for example).
from apollo-ios.
Happy to re-open discussion, because actual use cases and proposals are exactly what we need.
@KieranLafferty has been working on an apollo-codegen
Objective-C target.
We haven't thought about how this interacts with the runtime and which parts of the Swift code we can reuse however, and mixed language environments seem like a good use case to keep in mind.
I would definitely be in favor of a bridging solution, where we can reuse most of the runtime code and also share a single cache between languages.
Passing dictionaries seems like the easiest option. Using a reflection-based library like Wrap
works, but we may be able to do better by having the generated GraphQLMappable
types expose a dictionary
method (similar to how input objects currently expose graphQLMap
).
Of course, typed model classes would be a lot nicer. And if we can have them initialize themselves from the corresponding GraphQLMappable
(like the GraphQLNamedFragment
in your example) they won't have to contain much logic.
The benefit of this over a stand-alone Objective-C implementation is that result parsing relies on Swift typing magic, so keeping that in Swift and then bridging to Objective-C on demand means we don't have to reimplement this.
I'm also wondering if there is anything we can do to make bridging transparent by using _ObjectiveCBridgeable
, similar to how other value types are bridged in Swift 3.
from apollo-ios.
I only included the dictionary example as a simple, hacky workaround that one can actually use now to have a general way of exposing . I think it's not the right way to go forward. Exposing the dictionary
on GraphQLMappable
enables or even encourages unsafe usage of the API.
The proposal for ObjectiveCBridgeable is really awesome, very unfortunate that it is currently deferred. But, quoting the authors of the proposal:
For framework and library authors it presents an awful choice:
- Write mountains of glue code to convert between Swift and Objective-C versions of your types.
- Write your shiny new framework in Swift, but in an Objective-C style using only @objc types.
- Write your shiny new framework in Objective-C.
Choice #1 is not practical in the real world with ship dates, resulting in most teams choosing #2 or #3.
I think that their conclusion (choice 1 being impractical) is not completely relevant in our case, as we have the option to generate that code.
from apollo-ios.
Happy to re-open discussion, because actual use cases and proposals are exactly what we need.
@KieranLafferty has been working on an apollo-codegen Objective-C target.
@KieranLafferty any update?
from apollo-ios.
Just as a heads up: Given that it's been a few years and Swift has finally reached ABI stability (and module stability when 5.1 lands), we've officially decided not to move forward with Objective-C code generation on our end. You're definitely welcome to work on it on your own, but at this point it's just not on the priority list for Apollo directly.
Thanks very much for your patience, and sorry we weren't able to help here. I'm going to close this issue out.
from apollo-ios.
Related Issues (20)
- Support multiple schemas / endpoint in one project HOT 7
- Parity with Kotlin SDK for cache chaining and optimistic cache updates HOT 2
- PrivacyInfo.xcprivacy file is invalid for Apollo and ApolloApi. HOT 7
- SchemaConfiguration should be scoped within the namespace enum for `embeddedInTarget` module type
- Investigation: Allow codegen projects to modify generated filenames HOT 2
- Add support for incremental cache writes
- Add support for incremental cache reads
- Avoid File Overwriting for Unchanged Files HOT 1
- `InMemoryNormalizedCache` is a memory bomb HOT 5
- iOS 13.0 or newer error - compile fails HOT 3
- Custom Scalar | ApolloAPI.JSONDecodingError.couldNotConvert(value: AnyHashable to: Swift.String HOT 5
- How should I continue after handleErrorAsync inside a custom ApolloErrorInterceptor? HOT 5
- Defining a CustomScalarType which is [String:Any] HOT 12
- Deprecate `legacyResponse` and prepare for partial/incremental caching HOT 2
- Custom scalar isn't being respected HOT 7
- @defer issue HOT 8
- Documentation for @import directive. HOT 9
- Add debugDescription api for Apollo generated types
- Circular reference Build Error HOT 6
- Invalid redeclaration of synthesized property '_id' HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-ios.