GithubHelp home page GithubHelp logo

Comments (10)

kylesnipes avatar kylesnipes commented on August 20, 2024 4

@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.

kylesnipes avatar kylesnipes commented on August 20, 2024 1

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.

andrewpmoore avatar andrewpmoore commented on August 20, 2024

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.

andrewpmoore avatar andrewpmoore commented on August 20, 2024

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.

andrewpmoore avatar andrewpmoore commented on August 20, 2024

Has this been fixed or is there something we are doing wrong with the package?

from hasura_connect.

arpitjacob avatar arpitjacob commented on August 20, 2024

@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.

arpitjacob avatar arpitjacob commented on August 20, 2024

@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.

arpitjacob avatar arpitjacob commented on August 20, 2024

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.

happyfloat avatar happyfloat commented on August 20, 2024

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.

acamenhas avatar acamenhas commented on August 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.