Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Query resolver that uses an Observable or a websocket subscription that emit values but does not complete #532

Open
evertonrobertoauler opened this issue May 13, 2019 · 4 comments

Comments

@evertonrobertoauler
Copy link

It would be really nice, if we could use @Loona to query data on the client to fetch data from an Realtime database or an Websocket, like a Graphql Subscription but implemented in the client.

Now a resolver function work with Observables, but it gets and emits new values only when the Observable is completed.

In the current design of this library is it a way to add this functionality? @Urigo @kamilkisiela

@Urigo
Copy link
Collaborator

Urigo commented May 14, 2019

Can you set up a simple example we can collaborate on?

@evertonrobertoauler
Copy link
Author

https://stackblitz.com/edit/angular-hvefbv

src/app/books.state.ts

export class BooksState {
  @Resolve('Query.books')
  books() {
    return interval(1000)
      .pipe(map(i => [{ id: i + 1, title: 'Harry Potter', __typename: 'Book' }]))
      .pipe(first())
      .pipe(tap(i => console.log(i)))
      .pipe(shareReplay(1));
  }

This interval(1000) can represent a query to a Realtime database or a web socket, if you comment the line .pipe(first()) this observable will emit values but will not complete, as you will see, the books array will never show on screen.

This would be like a GraphQL Subscription.

@Urigo
Copy link
Collaborator

Urigo commented May 17, 2019

@evertonrobertoauler what real time solution would actually want to you?

@evertonrobertoauler
Copy link
Author

I'm using the Firebase Firestore database, reading more about the apollo client architecture, I came across the apollo link documentation, I believe this can be an alternative for me, do you believe that the best way for me to query and manipulate my firestore data using Graphql without the need for a graghql server is by creating my own apollo-link.

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

No branches or pull requests

2 participants