Skip to content
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

Null value when using Map over subscription #82

Open
victorths opened this issue Nov 30, 2020 · 4 comments
Open

Null value when using Map over subscription #82

victorths opened this issue Nov 30, 2020 · 4 comments

Comments

@victorths
Copy link

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
Copy link
Author

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: admin@email.com.br}, {email: otheremail@gmail.com}]}}

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: admin@email.com.br}, {email: otheremail@gmail.com}]}}
data: {data: {users: [{email: admin@email.com.br}, {email: otheremail@gmail.com}]}}

@Bwolfs2
Copy link
Member

Bwolfs2 commented Dec 1, 2020

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

@victorths
Copy link
Author

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: admin@email.com.br}, {email: otheremail@gmail.com}]}}

@levonmaa
Copy link

levonmaa commented Oct 3, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants