hasura_connect icon indicating copy to clipboard operation
hasura_connect copied to clipboard

Null value when using Map over subscription

Open victorths opened this issue 4 years ago • 4 comments

I have this code that works on hasura_connect version 1.2.2+1: return db.subscription(itensSubscriptionQuery).map((data) => data['data']['models'].map<Model>((t) => Model.toJson(t)).toList()); With the 2.0.0 update the subscription method became a Future, so a changed my code to something like this: return (await db.subscription(itensSubscriptionQuery)).map((data) => data['data']['models'].map<Model>((t) => Model.toJson(t)).toList()); But the map method aways return a null value on data.

If i change to somethig like this, it returns the data, but i lost the stream: (await db.subscription( "subscription MyQuery {users {email}} ", )).first

victorths avatar Nov 30 '20 18:11 victorths

I just ran some tests and it seems a bug indeed. If i run this code:

var sub = await db.subscription(
  "subscription MyQuery {users {email}} ",
);

sub.map((data) {
  if (data == null) {
    print('null');
  }
  print("data: " + data.toString());
});

print(await sub.first);

It will return:

null
data: null
{data: {users: [{email: [email protected]}, {email: [email protected]}]}}

but if i call the ".first" method before the .map like this:

var sub = await db.subscription(
  "subscription MyQuery {users {email}} ",
);

print(await sub.first);

sub.map((data) {
  if (data == null) {
    print('null');
  }
  print("data: " + data.toString());
});

Then the map methos no longer returns null and returns the right value:

{data: {users: [{email: [email protected]}, {email: [email protected]}]}}
data: {data: {users: [{email: [email protected]}, {email: [email protected]}]}}

victorths avatar Dec 01 '20 11:12 victorths

When do u work with Stream this Null result is expected, i forget to pass my sample tomorrow =/ Sample Code

Bwolfs2 avatar Dec 01 '20 12:12 Bwolfs2

I know that null is expeted, but it aways return null when i run the following code:

var sub = await db.subscription(
  "subscription MyQuery {users {email}} ",
);

sub.map((data) {
  if (data == null) {
    print('null');
  }
  print("data: " + data.toString());
});

print(await sub.first);

output:

// first null from 
// if (data == null) {
//    print('null');
//  }
null
// here shouldn't bee null because i check if it isn't null print("data: " + data.toString());
data: null
// but when i call .first it returns the data
{data: {users: [{email: [email protected]}, {email: [email protected]}]}}

victorths avatar Dec 01 '20 13:12 victorths

Any movement on this, still seems to be the case with version 4.0.0+4

levonmaa avatar Oct 03 '22 07:10 levonmaa