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

Support for subscribeToMore on query #120

Open
Ejhfast opened this issue May 1, 2020 · 3 comments
Open

Support for subscribeToMore on query #120

Ejhfast opened this issue May 1, 2020 · 3 comments

Comments

@Ejhfast
Copy link

Ejhfast commented May 1, 2020

Does the library support loading additional data from a subscription after a query is executed? Subscriptions are difficult to use efficiently without this functionality: https://www.apollographql.com/docs/react/data/subscriptions/#subscribetomore

To get around this I have been doing something like:

module Subscriber {
  [@react.component]
  let make = (~results) => {
    (subResults, _) = ApolloHooks.useSubscription(...);
    switch subResults {
      | Data(newResults) => <StatelessRenderer results=newResults />
      | _ => <StatelessRenderer results=results />
    }
  }
}

// parent component will query, then child will either pass data through 
// or re-render on subscription update
[@react.component]
let make = () => {
  (results, _) = ApolloHooks.useQuery(...);
  <Subscriber results=results />
}

But this has the major problem that each subscription push most contain all the data required to re-render a components, as opposed to an individual item to add, subtract, etc.

@MargaretKrutikova
Copy link
Collaborator

MargaretKrutikova commented May 3, 2020

I am pretty sure it is supported, here is where subscribeToMore is defined as a return value queryResult from useQuery. Can you check whether it will work for you?

@Ejhfast
Copy link
Author

Ejhfast commented May 4, 2020

Thanks, that looks very promising! Not sure how I missed it when I looked through the library. I'll close this issue once I confirm it's working -- will also try to do a pull request with some extra documentation.

@MargaretKrutikova
Copy link
Collaborator

That would be great 🙂

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