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

Intial refactoring to work over observables instead of promises #502

Closed
wants to merge 5 commits into from

Conversation

DxCx
Copy link

@DxCx DxCx commented Sep 23, 2016

First Implementation for #501 .
NOTE: Promises still works, this change does not break any existing usage.

TODO:

  • Get CR Notes.
  • Update any documentation? Which?
  • Replace Observables Library? set it to peer instead of dependency? pending a decision on issues.
  • Reactive Execution:
    • remove TODO and enable reactive execution.
    • write tests with reactive execution.
    • make sure to take(1) when non-reactive request executes and observable is resolved.

@ghost
Copy link

ghost commented Sep 23, 2016

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@ghost ghost added the CLA Signed label Sep 23, 2016
@ghost
Copy link

ghost commented Sep 24, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@DxCx
Copy link
Author

DxCx commented Sep 27, 2016

Hi @leebyron can you please review this?
I'm very eager to hear your thoughts about this :)

@leebyron
Copy link
Contributor

While I'm excited to support fields that return Observable values, I don't support this approach.

First, we shouldn't take a dependency on a large library like rxjs, either directly or as a peer dependency. Second, we should minimize the set of changes to the core executor. Third, we still need to support Promises/Thenable as the most common use case.

@ghost ghost added the CLA Signed label Sep 27, 2016
@leebyron
Copy link
Contributor

I'm in favor of continued experimentation in this area though. This is closely aligned with some other earlier experiments to add @LiVe to GraphQL.

@DxCx
Copy link
Author

DxCx commented Sep 27, 2016

Hi @leebyron thanks for the quick response :)
I agree about the rxjs dependency, that's why i've opened it under discuession, and pending to hear what do you think should be supported..
also, if you will note, i did the minimal change to run over observables rather then promises.
then, in the end of the pipe, execute converts the observable into a promise, so no interface is broken.
and promises are still supported.

@leebyron
Copy link
Contributor

Another question is what we actually want to see from a reactive GraphQL executor. We probably do not want to re-execute fields that are likely to have not changed and the output should be a series of diffs to send over the network rather than a series of whole values

@DxCx
Copy link
Author

DxCx commented Sep 27, 2016

hehe, seems that we are aligned, just released today rxjs-diff-operator which is exactly for that purpose.

the update logic is same as the old one,
so basically, static values will not be re-executed,
promises are Observables.fromPromise(1) which is observable of 1 value, so they won't re-execute either.
the only re-execution that may occur is when the subscription resolver returns an Observable,
then for each value emitted (next called by the observer), the ObjectType resolvers will be updated with a new root value from the subscription, however, this is the expected behavior as i see it.
Also note that all the existing tests are passing with no modification.

@ghost ghost added the CLA Signed label Sep 27, 2016
@DxCx
Copy link
Author

DxCx commented Sep 28, 2016

hi @leebyron, eventually i decided to create a seperated npm (graphql-rxjs) package for this for the moment being.
this way i can experiment it myself,
i'm planing on creating example app that uses it so you can experiment yourself.

@ghost ghost added the CLA Signed label Sep 28, 2016
@stubailo
Copy link
Contributor

Really excited to see where this goes. I think observables in the resolver return can be a neat way to do subscriptions as well.

@DxCx
Copy link
Author

DxCx commented Oct 29, 2016

hi @leebyron,

i have a server side example (getting graphiql with subscription over observables)
i thought i posted it a while ago and now i see that i didn't :(

so, if you want to take a look,
https://github.com/DxCx/webpack-apollo-server/tree/rxjs-subscriptions
specifically, on main.ts i define a channel (https://github.com/DxCx/webpack-apollo-server/blob/rxjs-subscriptions/src/main.ts#L15)
and then i use it inside a resolver (https://github.com/DxCx/webpack-apollo-server/blob/rxjs-subscriptions/src/schema/modules/subscription.ts#L10)

if you want to really play with it, just clone it (note this is rxjs-subscriptions branch), and then npm install & npm start.
then you will have a graphiql interface with the subscription on port 3000.

Other then that, i'm not sure what are you against in here,
are you against for the general concept of using Observables along with promises? (which feels much more intuitive versus the pub/sub solution found today)
or for the dependency of rxjs?

also, once this is resolved i would be happy to work on the @defer/@live/@stream directives as well as with observables it's very easy to implement.

@DxCx
Copy link
Author

DxCx commented Nov 10, 2016

@leebyron can you please reply?

@leebyron
Copy link
Contributor

Hey @DxCx, sorry for the delayed response.

Since this library primarily serves to be a production node server and reference implementation of the spec, I don't think it's the appropriate place for this kind of experimentation for fear that other implementations would see it as part of the direction of GraphQL, and this is not yet what we'd like to do.

Notably - it's important that the execution code align to the spec to be a good reference implementation.

I do think it's a great idea to experiment with observable-based resolvers, it's an exciting idea that deserves to be explored - but I think that exploration deserves it's own repository which can move quickly and experiment with different ideas without worrying about breaking core users.

@leebyron
Copy link
Contributor

I'm going to close this PR since we don't want to pursue this in this repository - I'm looking forward to seeing your work as a separate package.

@leebyron leebyron closed this Nov 15, 2016
@DxCx
Copy link
Author

DxCx commented May 17, 2017

hey @leebyron
after seen the work on subscription i was thinking,
if i'll rewrite this using AsyncIterator instead of Observables, is that something you will accept?

i mean, i want to introduce some execute function (executeReactive?) which is able to return more then one result potentially.

@smkhalsa
Copy link

Hey @leebyron,

Now that AsyncIterator has reached Stage 4, I'd love to hear your thoughts on @DxCx 's proposal above to add AsyncIterator support to the execute function. The ability to return multiple results from the execute function would be a huge step forward for live queries. Thanks!

@leebyron
Copy link
Contributor

leebyron commented Feb 17, 2018 via email

@smkhalsa
Copy link

@leebyron That makes sense. I believe that @DxCx 's graphql-rxjs takes this approach, with a separate executeReactive executor.

Would you consider a PR for adding reactive executors to the library at this time? Thanks again!

@leebyron
Copy link
Contributor

leebyron commented Feb 18, 2018 via email

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

Successfully merging this pull request may close these issues.

None yet

5 participants