Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish API should be removed (me thinks) #15

Closed
gluck opened this issue Oct 20, 2016 · 11 comments
Closed

Publish API should be removed (me thinks) #15

gluck opened this issue Oct 20, 2016 · 11 comments

Comments

@gluck
Copy link
Contributor

gluck commented Oct 20, 2016

How one want to publish shouldn't matter to the SubscriptionManager, as the correct way to publish messages is through the onMessage callback.
I think the publish methods on PubSub and SubscriptionManager are confusing, as you can implement a correct (for now) server without them.

E.g. I implemented a PubSub based on Observables:

    pubsub: {
      subscribe(triggerName, onMessage, channelOptions) {
        return Promise.resolve(channelOptions.resolve$.subscribe(onMessage, console.error))
      },
      unsubscribe(subscription) {
        subscription.unsubscribe()
      }
    },

No need for publish (and I wouldn't know how to implement it if I wanted to).

It's fine for the default in-memory-event-based-pubsub-implementation to have a publish method, but it shouldn't be in the interface or wrapped in SubscriptionManager.

Thx.

@stubailo
Copy link
Contributor

I think you're right - this also came up in #13

@gluck
Copy link
Contributor Author

gluck commented Oct 24, 2016

I can PR that if you'd like, either by dropping the method entirely or dropping its definition/documentation/uses but keeping it (with a console warning) for backward (do we care at this stage ?).

Thx

@gluck gluck mentioned this issue Oct 24, 2016
@helfer
Copy link
Contributor

helfer commented Oct 24, 2016

Yeah, a PR would be great! Thanks @gluck

@DxCx
Copy link

DxCx commented Oct 24, 2016

This is not pubsub based on obsevables im sorry
You are replacing one broken api with a mutation of the existing one.

If you want observable based api, then a resolver should return an observable.

@helfer
Copy link
Contributor

helfer commented Oct 25, 2016

@DxCx We're interested in improving the current implementation, and rewriting graphql-js isn't in scope. What we're doing is very closely aligned with what FB does internally, and I think it makes sense to keep it that way for now.

@gluck
Copy link
Contributor Author

gluck commented Oct 25, 2016

To me, Observables are a neat match for pubsub, Rx Subject concept is very much that.
That being said my graphQL resolvers are also Observables (to which I apply .take(1).toPromise() before passing them to graphql-js).

If you suggest (query) schema resolvers (as observables) can be leveraged for realtime updates (@live ?), I'm interested, because I haven't found how to do that.

@DxCx
Copy link

DxCx commented Oct 26, 2016

then take a look at this: https://github.com/DxCx/webpack-apollo-server/blob/rxjs-subscriptions/src/schema/modules/subscription.ts#L10
note that clockSource is Observable (https://github.com/DxCx/webpack-apollo-server/blob/rxjs-subscriptions/src/main.ts#L15)

graphql-rxjs is a modified graphql library which has observables support,
at the moment i'm working to provide a full example (server-client) usecase (although i dont have the time i want those days to progress as i want :() then i believe it will be merged to offical graphql package.

@thebigredgeek
Copy link

thebigredgeek commented Oct 31, 2016

@gluck Yeah can we please NOT make Apollo or any of it's GraphQL componentry dependent on RxJS? That would create a lot of unnecessary overhead on the client to load such a massive library that is only going to be used in a couple of places. I personally think that it's overengineering to do so. Having a really simple API for pub/sub seems fine to me. If people wanna use Rx in their apps they can just create subjects or observables and wrap APIs with them. I don't think mandating usage is a great idea.

@gluck
Copy link
Contributor Author

gluck commented Nov 1, 2016

@thebigredgeek I wasn't advocating for rxjs dependency, and I agree it would be a bad idea for a core library.
Though you can support ES7 observables along with promises with no extra dependency (duck typing), and that's usually a good idea IMO, e.g. That's what graphIQL does.

@thebigredgeek
Copy link

thebigredgeek commented Nov 2, 2016

Awesome. Sorry I think my typo of putting of not putting NOT in my first sentence might have caused this to come across as edgy, which was not intended. Just edited

@dotansimha
Copy link
Contributor

@gluck
A lot has changed since this issue, and now SubscriptionsManager is deprecated, and the PubSub no longer attached to the subscriptions handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants