-
Notifications
You must be signed in to change notification settings - Fork 132
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
introduce GraphQLExecutorWithSubscriptions #47
Conversation
package.json
Outdated
@@ -8,7 +8,8 @@ | |||
"url": "/~https://github.com/apollostack/graphql-subscriptions.git" | |||
}, | |||
"dependencies": { | |||
"es6-promise": "^3.2.1" | |||
"es6-promise": "^3.2.1", | |||
"graphql-server-observable": "file://../graphql-server/packages/graphql-server-observable" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pending merging of apollographql/apollo-server#308
Why does this code need to be inside this package? Can't it just go into your |
I can wrap it the other way around and give it another package inside graphql-server, |
Is the main goal here to make the subscription return an observable instead of the callback style? Or does it also do something else? |
After looking at the code I think it could be a really great change, but it would be a lot easier to look at it if there was a description about what it is trying to achieve. I agree it is a good idea to have an execution function that decides whether to run a subscription or a static query, but it wasn't clear at first that this is what the PR is doing. |
Sorry @stubailo
This way people can migrate easily from running on both http and websocket to run all operations on a single websocket connection. |
Is there any reason it's split into two steps like that? Why not:
Right now you have to initialize the executor and then call execute but it could just be one function I think? |
But the idea is to be comeptiable with graphql execute engine step. |
If the main goal was to just introduce obeservable that was probably right, but as ive said i wanted the code to be more reusable in general.. |
But it still won't be a simple replacement right, since const graphql = createGraphQLExecutorWithSubscriptions(...);
const resultObservable = graphql(...); Then it will be even more interchangeable? |
Well, the same interface, but instead of a promise, an observable, so more then one value can be emitted. Why would returning a factory will be better? |
Because it's more similar to the original |
But it also exports execute which is just the execute step.
Original apollo runQuery runs the execute step, thats the reason i made it
symmetrical with execute..
…On Thu, 23 Feb 2017 at 20:27 Sashko Stubailo ***@***.***> wrote:
Because it's more similar to the original graphql API? graphql-js exports
a function, so this would be more consistent with how people are used to
consuming that API. (In your case I think you're creating a class with one
method on it, which is a pretty different API)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#47 (comment)>,
or mute the thread
</~https://github.com/notifications/unsubscribe-auth/ABB8WwGvKwP7SpwYBQ6u-8zFAbxXDDIrks5rfc9_gaJpZM4MFC-g>
.
|
OK I think that's fine - I think @Urigo should review. My last opinion here would be that |
Well, as i said, i can do the exact opposite, the truth is that i started
this way - so i can easily revert changes..
But, then i realized that there is alot of logic running for nothing and
the right thing is to do just the opposite (extract the minimum logic so
both packages can use just it)
So eventually, the users still can use their existing
pubsub/setupFunctions/schema but constructing different objects..
…On Thu, 23 Feb 2017 at 22:39 Sashko Stubailo ***@***.***> wrote:
OK I think that's fine - I think @Urigo </~https://github.com/Urigo> should
review.
My last opinion here would be that GraphQLExecutorWithSubscriptions
should ideally take an entire SubscriptionManager object as one argument,
so that we don't have to document those arguments twice (since it takes
basically the same things).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#47 (comment)>,
or mute the thread
</~https://github.com/notifications/unsubscribe-auth/ABB8W-pfCZPcV7I_X1uupA9H3b20K0nkks5rffyFgaJpZM4MFC-g>
.
|
…ak legacy BREAKING CHANGE: - removed publish from SubscriptionManager. - tests once assumed publish is async and once sync, looks like there was no default behavior. This commit sets publish to run onNextTick, this way, once unsubscribe is called, you are guaranteed not to get callback called again.
this PR is ready to be merged. 👍 |
this.pubsub = options.pubsub; | ||
} | ||
|
||
public executeReactive( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like this should be using an object to pass in arguments. Likewise for execute
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to have the same signature as original's graphql execute..
@@ -36,13 +21,15 @@ export class PubSub implements PubSubEngine { | |||
} | |||
|
|||
public publish(triggerName: string, payload: any): boolean { | |||
this.ee.emit(triggerName, payload); | |||
process.nextTick(() => this.ee.emit(triggerName, payload)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment about why the nextTick
is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont remember the exact issue, but it is related to how the tests assume data is handled.. i can dig in again
.subscribe({ | ||
next: (v) => { | ||
resolve(v) | ||
process.nextTick(() => sub.unsubscribe()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment about why nextTick
is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you want to make sure sub is resolved with a value.
resolve(v) | ||
process.nextTick(() => sub.unsubscribe()); | ||
}, | ||
error: (e) => reject(e), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also have to unsubscribe in the error case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats on the observer's duty, it might just unsubscribe or handle the error if it wants too, but we shouldn't unsubscribe for the user
@Urigo you forgot about this PR that addes GraphQLExecutorWithSubscriptions. |
@DxCx I have not :) please check out my comment here - apollographql/subscriptions-transport-ws#108 (comment) |
well, looks like executor pattern was removed in (apollographql/subscriptions-transport-ws#133) which means there is not reason to keep that PR.. |
Hey,
I've refactored
graphql-subscriptions
so the execution logic will be isolated then the SubscriptionManager.With this executor we will support subscriptions for the new
graphql-server-ws
package.This PR also adds support for query/mutation.
TODO: