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

[RFC] Support a fetcher that returns Observable #104

Merged
merged 1 commit into from
Mar 9, 2016
Merged

Conversation

leebyron
Copy link
Contributor

@leebyron leebyron commented Mar 9, 2016

This supports the fetcher returning an Observable, which will let us begin to experiment with support for GraphQL subscriptions and observable "live queries".

To test this, I added the crappiest possible Observable implementation to example/index.html:

if (graphQLParams.query.indexOf('subscription') === 0) {
  // If the operation smells like a subscription (#clowntown) then return an "Observable".
  return {
    // The subscribe function accepts an "Observer" which has next, error, and complete functions.
    subscribe(observer) {
      try {
        var i = 0;
        var interval = setInterval(() => {
          if (i > 10) {
            clearInterval(interval);
            observer.complete && observer.complete();
          } else {
            observer.next && observer.next({ data: i++ });
          }
        }, 500);
      } catch (e) {
        clearInterval(interval);
        observer.error && observer.error(e);
      }

      // Return a "Subscription" object with an unsubscribe function.
      return {
        unsubscribe() {
          clearInterval(interval);
        }
      };
    }
  };
}

Read more about Observable

This supports the fetcher returning an Observable, which will let us begin to experiment with support for GraphQL subscriptions and observable "live queries".

To test this, I added the crappiest possible Observable implementation to example/index.html:

```js
if (graphQLParams.query.indexOf('subscription') === 0) {
  return {
    subscribe(observer) {
      try {
        var i = 0;
        var interval = setInterval(() => {
          if (i > 10) {
            clearInterval(interval);
            observer.complete && observer.complete();
          } else {
            observer.next && observer.next({ data: i++ });
          }
        }, 500);
      } catch (e) {
        clearInterval(interval);
        observer.error && observer.error(e);
      }
      return {
        unsubscribe() {
          clearInterval(interval);
        }
      };
    }
  };
}
```
leebyron added a commit that referenced this pull request Mar 9, 2016
[RFC] Support a fetcher that returns Observable
@leebyron leebyron merged commit c454f66 into master Mar 9, 2016
@leebyron leebyron deleted the observable branch March 9, 2016 01:30
acao pushed a commit to acao/graphiql that referenced this pull request Jun 1, 2019
…transform-regenerator-6.22.0

Update babel-plugin-transform-regenerator to the latest version 🚀
acao pushed a commit to acao/graphiql that referenced this pull request Jun 5, 2019
Guard against hoistDependencies foot-gun
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.

2 participants