Closed moehmeni closed 2 years ago
@mdmomeni Thanks for reporting this! Do you mind sharing how you're initializing the client? Specifically, how are you providing the Hive box to the client.
My main
function:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize Firebase
await FCM.init();
// Initialize Hive (from GraphQL package)
await initHiveForFlutter();
// Initialize UserController Hive box
await UserController.init(); // await Hive.openBox<String>("user");
// GraphQL
final HttpLink httpLink = HttpLink(
"http://10.0.2.2:8000/graphql",
);
final AuthLink authLink = AuthLink(
getToken: () => UserController.token,
);
final Link link = authLink.concat(httpLink);
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
link: link,
cache: GraphQLCache(store: HiveStore()),
),
);
runApp(MyApp(client));
}
Also MyApp
:
class MyApp extends StatelessWidget {
const MyApp(this.client, {Key? key}) : super(key: key);
final ValueNotifier<GraphQLClient> client;
@override
Widget build(BuildContext context) {
return GraphQLProvider(
client: client,
child: GetMaterialApp(
...
Client provider:
GetBuilder<SearchController>(
init: SearchController(),
builder: (_) {
return GraphQLConsumer(builder: (client) {
return Expanded(
child: Column(children: [
searchField(client, _),
const SizedBox(height: 10),
Expanded(
child: Stack(
alignment: Alignment.center,
children: [mainBody(_), submitBtn()],
))
]));
});
}),
...
Widget searchField(GraphQLClient client, SearchController _) {
return Padding(
padding: const EdgeInsets.all(10),
child: TextField(
textDirection: TextDirection.ltr,
decoration: CInputDecoration(hintText: "جستجو"),
onChanged: (q) => onInputChange(q, client, _),
),
);
}
Cheers @mdmomeni! I've created a PR with a fix. If you're able to verify that it's working for you, that'd be a huge help!
Thank you, but how can I replace the updated code? and should I review the PR or something after testing it?
@mdmomeni
You should be able to add the branch as a dependency directly. I.e., update your pubspec.yaml
file with
graphql_flutter:
git:
url: git://github.com/zino-hofmann/graphql-flutter.git
ref: fix-hive
path: packages/graphql_flutter
I'm not sure if you can add a review, but a comment on the PR (or here) will be fine.
@mdmomeni
You should be able to add the branch as a dependency directly. I.e., update your
pubspec.yaml
file withgraphql_flutter: git: url: git://github.com/zino-hofmann/graphql-flutter.git ref: fix-hive path: packages/graphql_flutter
I'm not sure if you can add a review, but a comment on the PR (or here) will be fine.
@budde377 The exception still exists. When I set fetchPolicy to FetchPolicy.networkOnly, this problem does not exist. But I set it to FetchPolicy.cacheAndNetwork, and this exception occurred. I guess that the data type stored in hive does not match the Map.
This is my data structure:
[
{
_id: 6141e5e09fa3f5afd79e6ecb,
type: urlLaunch,
content:
{
image: image1.png,
url: https://example1.com,
},
__typename: Recommend,
},
{
_id: 6141e8029fa3f5afd79e6ecc,
type: urlLaunch,
content:
{
image: image.png,
url: https://example.com,
},
__typename: Recommend,
},
]
I use fast_immutable_collections
and freezed
@freezed
class Recommend with _$Recommend {
factory Recommend({
required String type,
required IMap<String, String> content,
}) = _Recommend;
factory Recommend.fromJson(Map<String, dynamic> json) =>
_$RecommendFromJson(json);
}
void exampleQuery () {
final result =
await client.query$Recommend(Options$Query$Recommend(
operationName: 'exampleQuery',
fetchPolicy: FetchPolicy.cacheAndNetwork,
variables: Variables$Query$Recommend(
memberId: memberId,
),
));
if (result.hasException) {
handleException(result);
throw Exception(result.exception.toString());
}
final recommendList = IList.fromJson(
/// 🔨 If I want to not report this exception, I need to do the following
/// FIX: should work code json.decode(json.encode(result.data?["exampleQuery"]))
result.data?["exampleQuery"],
(dynamic item) => Recommend.fromJson(item),
);
return recommendList;
}
Thanks for reporting. Please check if #1167 fixes this for you! @Adherentman
Thanks for reporting. Please check if #1167 fixes this for you! @Adherentman
@budde377 I checked the relevant code and it should solve the problem。 But I have a problem trying to use the latest code in pubspec.yaml.
graphql:
git:
url: https://github.com/zino-hofmann/graphql-flutter.git
ref: main
path: packages/graphql
graphql_flutter:
git:
url: https://github.com/zino-hofmann/graphql-flutter.git
ref: main
path: packages/graphql_flutter
get error:
Because every version of graphql_flutter from git depends on graphql from hosted and example_app depends on graphql from git, graphql_flutter from git is forbidden.
So, because example_app depends on graphql_flutter from git, version solving failed.
pub get failed (1; So, because example_app depends on graphql_flutter from git, version solving failed.)
Or when will it be published on pub.dev
this is your error, you should put also inside the override package the graphql, this tell to pub "Hey you are using git, but there is some depenciences in common, so ignore it and use git".
It is strange, but the dependieces resolution world is more strange.
BTW I'm releasing the new beta release later in the day
I have used main branch to verify that it runs very well. Thank you.
@Adherentman the new beta is out
This is the error when I try to run
client.query
with aGraphQLConsumer
foronChanged
event of aTextField
seems there is an issue during encoding/decoding the API result into the Hive box (it's weird it was working as expected yesterday while I did not change the code and today it has issues)
Expected behavior Get the result from
client.query
and update the view (using aGetx
controller sinceQuery
was not working as expected)device / execution context Android simulator
The event function:
Stacktrace:
```dart E/flutter (23039): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type '_InternalLinkedHashMap