kamilkisiela / loona

🌕 Application State Management done with GraphQL
https://loonajs.com
MIT License
265 stars 14 forks source link

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

Open evertonrobertoauler opened 5 years ago

evertonrobertoauler commented 5 years ago

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 commented 5 years ago

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

evertonrobertoauler commented 5 years ago

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 commented 5 years ago

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

evertonrobertoauler commented 5 years ago

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.