Comments (10)
@arpitjacob Let's say you have a simple query like
subscription GetThing($id: Int!) { id }
If you call subscribe with that query with the variables {'id': 0}, it'll successfully return what you expect. If however, you then call subscribe again with the same query but {'id': 1}, the subscription where id = 0 is returned because the client caches subscriptions based on query only. In this case, both subscriptions share a query but different variables.
The subscriptions are wrapped in a class called SnapShot which allows you to dispose and change variables. There does not appear to be a way to successfully subscribe to a query twice with different variables though.
My workaround is to use something like
subscription GetAllThings() { id }
and then using RxDart to split that stream into streams containing the individual things.
from hasura_connect.
My issue ended up being the result of something else. Digging into it, the snapmap in HasuraConnectBase used for caching subscriptions uses a key based off the query only and does not include the variables. So if you attempt to subscribe to two queries differing only in variables, it'll always return the first one that was cached in snapmap.
from hasura_connect.
I'm having similar problems, @kylesnipes have you tried playing around passing a unique key into the subscription (there's an optional parameter for a key).
I do that, but then instead of getting back the old data, I'm now getting back no data on the 2nd call.
from hasura_connect.
I've found out that I don't have this issue on version 1.1.2 of the package. It get's the correct data.
from hasura_connect.
Has this been fixed or is there something we are doing wrong with the package?
from hasura_connect.
@kylesnipes could you explain this and give an example, I have the same issue, I am using a subscription to which I pass data and the variables change but only the first result is loaded every-time.
from hasura_connect.
@kylesnipes oh thank you so much, and thanks for the quick reply, I've been struggling with this the last 3 days, that makes so much sense I thought something was wrong with the way I was implementing Provider, StreamProvider.
Unfortunately if I go with your approach it will load too much data, I need to load data based on a variable.
So looks like this is a problem with the package.
from hasura_connect.
Ahhh I read through the documentation again I missed this, I got it working now when I pass a different variable value it updates the subscription.
Snapshot snapshot = hasuraConnect.subscription(docSubscription, variables: {"limit": 10});
//change values of variables for PAGINATIONS
snapshot.changeVariable({"limit": 20});
from hasura_connect.
This needs to be documented better. Also it is really limiting to be able to only have one subscription at a time... I can not just subscribe to all my content... I should only do that for the content which is currently visible. I'm new to dart and flutter, so I'm not feeling confident enough to dig deeper into the lib and create a PR... maybe later then.
Edit: Ok, instead of subscribing to all, I could subscribe to where: {id: {_in: ""}}
or something like that.
from hasura_connect.
I also have this problem...
In my case I have 2 modules: employees and employee.
In the employees list when I click on an item, I pass the id as an argument and push the employee module to show his data (in a form) with this subscription:
@override
Stream<EmployeeModel> getEmployee(int id) {
return connect.subscription(employeeQuery, variables: {"id": id}).map((json) {
return EmployeeModel.fromJson(json['data']['employees'][0]);
});
}
When I pop and click on a new item, the new id as passed but the same employee data is showed.
I don't know if there's a problem with the dispose, or with the caching, if you do a little demo you can see this problem happening.
If it's related with the package I think that's important to solve, because it's a feature that is used in various modules by everyone that works with subscriptions.
Thanks,
Artur
from hasura_connect.
Related Issues (20)
- Quick question about sending x-hasura-admin-secret to access grapql access point HOT 2
- Error: The argument type 'String' can't be assigned to the parameter type 'Uri'. HOT 2
- Hi,this project is abandoned?
- Subscriptions stop working when app goes in backgroup, do not work anymore until I restart HOT 2
- hasura_connect and hasura_cache_interceptor don't match the version HOT 2
- meta ^1.8.0 HOT 3
- Add executeQuery, executeSubscriptio and executeMutation in the documentation
- bump either_dart from ^0.1.3 to ^0.2.0 HOT 2
- The method '[]' was called on null Receiver: null HOT 1
- Subscription will not work with Stream, return type is changed as future. How can we implement in new version with flutter. HOT 3
- Does the package have Request Timeout? HOT 1
- Trocar either_dart por result_dart HOT 1
- Subscription stop working when connection drop.
- Starting two different subscriptions at the same time throws "an operation already exists with this id" HOT 6
- Unhandled Exception: ConnectionError: Websocket Error HOT 5
- Null Safety Version HOT 1
- headers could be Map<String, dynamic>? instead of Map<String, String>? HOT 1
- open source hasura HOT 2
- invalid url for websocket connection in dev environment HOT 1
- Flutter Web dont' work with null safety HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hasura_connect.