Combine `subscribe` with `execute`?
See original GitHub issueRight now, subscribe and execute are two functions. And there are some issues with that.
- Semantically, subscription is a type of execution. In the spec, Query, Mutation and Subscription are on the same level. Subscription is not an outlier.
- When I get a Document, I need to go through validations to get the Operation, and then call
executeorsubscribebased on Operation’s type, and they go through a similar validation, resulting in duplicated work.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Receiving and Handling Events with Combine
The first closure executes when it receives Subscribers. ... If you no longer want to subscribe to the publisher, you can cancel the...
Read more >subscribe(on:) vs receive(on:) - try Code
subscribe (on:) sets the scheduler on which you'd like the current subscription to be “managed” on. This operator sets the scheduler to use...
Read more >Combine`s subscribe(on:options:) operator - Stack Overflow
Specifies the scheduler on which to perform subscribe, cancel, and request operations. In contrast with receive(on:options:), which affects ...
Read more >Getting Started with Combine in Swift - Medium
Subscribing to a Simple Publisher The Combine Framework adds a publisher property to an Array. We can use this property to turn an...
Read more >Understanding Combine's publishers and subscribers
A publisher/subscriber relationship in Combine is solidified in a third object, the subscription. When a subscriber is created and subscribes to ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Just happened this use-case. As a user, my initial expectation was that I would be able to do
query.execute. I was initially surprised to learn that subscription was a separate method.But I sympathize with how the polymorphic type this would result in could hurt DX.
A new TS generic parameter and/or casting could do their bit to help, but only modestly.
Most of the time, in practice, what would probably happen, is users narrowing the result before using it.
In the end, having the API allow to do this branching up front (method selection vs result narrowing) seems very reasonable.
I don’t see a “best” option here. Maybe both, e.g.:
I don’t know if splitting Query / Mutation for API symmetry has any functional benefit here. Maybe that’s acceptable, not sure.
@IvanGoncharov , thanks again for you reply.
buildExecutionContextis indeed very helpful. I think I’ll use it for now.