-
Notifications
You must be signed in to change notification settings - Fork 109
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
Forward the subscribeToMore option to enable usage from useQuery #35
Conversation
I did not see subscribeToMore in the observer. Did you test it ? Is it working ? |
Hi @seeden , indeed it is part of the prototype of ObservableQuery from apollo-client/core link and is available in the returned observableQuery. The relevant excerpt of calls is useQuery -> getCachedObservableQuery -> watchQuery -> instance of ObservableQuery -> public method subscribeToMore It's not visible directly, because it's inside the |
Great sounds good. I can not wait :) |
@dimitar-nikovski Thanks for your PR, but I'm not sure if it's a good idea to use |
I want to use it like this: export default (query, options: Options = {}): Object => {
const { onReady, ...rest } = options;
const [subscribed, setSubscribed] = useState(false);
const response = useQuery(query, {
suspend: false,
...rest,
});
const { loading, error } = response;
if (error) {
throw error;
}
if (!loading && !subscribed && onReady) {
setSubscribed(true);
onReady(response);
}
return response;
}; useQuery(query, {
onReady({ subscribeToMore } => {
...
}),
}) I have tried it few weeks ago but there was no subscribeToMore function :) In this moment I am using |
|
|
@trojanowski I was thinking about it and I recommended to use both
If it is possible please merge this commit. It will be really helpful for me in this moment |
SubscribeToMoreOptions<TData, TVariables, TSubscriptionData>, | ||
'updateQuery' | ||
> & { | ||
updateQuery: UpdateQueryFn<TData, TVariables, TSubscriptionData>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateQuery is optional in the apollo client typings, however, without it, subscribeToMore has no side effects, see code
document !== previousSubscription.current || | ||
isEqual(variables, previousSubscribtionOptions.current) | ||
) { | ||
unsubscribeToMore.current = observableQuery.current.subscribeToMore( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subscribeToMore
returns a function to unsubscribe from the subscription see here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conditional mistake corrected in the commit below
Hi @seeden, now it should be much better, as @trojanowski pointed out, there are necessary conditions to set it up properly. I don't expect it to be merged, unless there is genuine desire from more people for it to be part of the project, for me, it mainly helps with the convenience of merging the subscription updates back into the store with
Conveniently, when merging the results in |
Hi @dimitar-nikovski thank you for your update 👍. Actually I am using subscribeToMore only with updateQuery. But it is related to useQuery because I am using old query result in the updateQuery (it is standard in the react-apollo and Query component I guess). I am merging edges most of the time. |
I ought to add some tests, just in case it will be going further. |
What do you think about the API suggested in #37 (comment)? It would allow to update any previous query. |
Do you think it would solve all your use cases for subscribeToMore or you still need it? |
@trojanowski it's cleaner indeed, we can use the subscription result from useSusbscription and the updateQuery prop form ObservableQuery returned by useQuery and achieve the exact same result. Feel free to close this down. |
No description provided.