Comments (6)
Hey @rutaba1 is your backend GraphQL operation a subscribe
operation or a get
operation?
If you're calling a get
operation, then subscribe
will only add a new event to the stream when local data satisfying the subscribe
query is changed in the SQLite db.
from brick.
@tshedor It is a subscribe operation and I'm even overriding the subscribe
function in my GraphqlQueryOperationTransformer but still no luck.
@override
GraphqlOperation? get subscribe => const GraphqlOperation(
document: r'''
subscription Subscription{
todo_mutated {
key
event
data {
title
id
}
}
}''',
);
I'm getting an error in console now with no realtime behaviour
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast
E/flutter (19394): #0 _$TodoFromGraphql (package:brick_graphql_test/brick/adapters/todo_adapter.g.dart:8:30)
E/flutter (19394): #1 TodoAdapter.fromGraphql (package:brick_graphql_test/brick/adapters/todo_adapter.g.dart:95:13)
E/flutter (19394): #2 GraphqlProvider.subscribe (package:brick_graphql/src/graphql_provider.dart:131:27)
I'm printing the values from $TodoFromGraphql function in generated adapter and I'm getting this:
MAP______{id: 86, title: Test}
MAP_______{id: 87, title: Fielder}
MAP_______{todo_mutated: null}
Here 1st and 2nd are valid but 3rd is not
from brick.
@rutaba1 can you please provide your Todo
model? When you say "printing the values" does that mean you're doing print(data)
?
from brick.
@tshedor Yeah,here is my model
@ConnectOfflineFirstWithGraphql(
graphqlConfig: GraphqlSerializable(
queryOperationTransformer: TodoQueryOperationTransformer.new,
))
class Todo extends OfflineFirstWithGraphqlModel {
@Sqlite(unique: true)
final String id;
final String title;
Todo({
required this.id,
required this.title,
});
}
and in todo_adapter.g.dart
I am printing the value here.
Future<Todo> _$TodoFromGraphql(Map<String, dynamic> data,
{required GraphqlProvider provider,
OfflineFirstWithGraphqlRepository? repository}) async {
print('MAP_______${data}');
return Todo(id: data['id'] as String, title: data['title'] as String);
}
from brick.
@rutaba1 ah, I see. Brick expects the fields you list within the operation to map as top-level properties for the Dart instance fields. For example, the expected Dart model would be
@ConnectOfflineFirstWithGraphql(
graphqlConfig: GraphqlSerializable(
queryOperationTransformer: TodoQueryOperationTransformer.new,
))
class Todo extends OfflineFirstWithGraphqlModel {
final String key;
final String event;
final Map<String, dynamic> data;
Todo({
required this.key,
required this.event,
required this.data,
});
}
If you want to use the nested properties of data
as instance fields in Dart, you'll need to do some custom remapping:
@ConnectOfflineFirstWithGraphql(
graphqlConfig: GraphqlSerializable(
queryOperationTransformer: TodoQueryOperationTransformer.new,
))
class Todo extends OfflineFirstWithGraphqlModel {
@Sqlite(unique: true)
@Graphql(fromGenerator: "(data['data'] as Map)['id'] as String")
final String id;
@Graphql(fromGenerator: "(data['data'] as Map)['title'] as String")
final String title;
Todo({
required this.id,
required this.title,
});
}
from brick.
@rutaba1 going to close this due to inactivity
from brick.
Related Issues (20)
- Function afterSave() is generated wrong HOT 7
- databaseFactoryFfi not save data in local HOT 1
- Outdated package dependencies HOT 1
- Support to windows not work HOT 3
- Adapter file not generated when uniquely identified field is a class and no primitive HOT 14
- multipart request HOT 8
- Feature: Support for more database adapters HOT 2
- Relative imports in models are not correctly transferred to brick.g.dart HOT 2
- Question (Perhaps Not an Issue) About topLevelKey HOT 2
- Dependencies Issue HOT 2
- Getting POST When I Need PUT HOT 5
- Handling Expired Access Keys in Offline Request Queue HOT 2
- Question: How to correctly upsert an association to a REST Provider? HOT 6
- Proposal: add the response details to the offline request queue HOT 4
- Documents that do not exist remotely are not deleted from local memory HOT 1
- Remove Items From Outbound Queue HOT 4
- Problem Re-initializing HOT 8
- Duplicate Column in Migration Script HOT 6
- Read from REST but Don't Write Back to REST HOT 3
- Unexpected Remote Provider Calls for Associated Data HOT 2
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 brick.