hasura_connect
hasura_connect copied to clipboard
Null value when using Map over subscription
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
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]}]}}
When do u work with Stream this Null result is expected, i forget to pass my sample tomorrow =/ Sample Code
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]}]}}
Any movement on this, still seems to be the case with version 4.0.0+4