graphql-flutter icon indicating copy to clipboard operation
graphql-flutter copied to clipboard

[QUESTION] Why is GraphQLProvider dependent on ValueNotifier<GraphQLClient>

Open theGlenn opened this issue 4 years ago • 1 comments

The docs stipulate 👍 that When [value] is replaced with something that is not equal to the old value as evaluated by the equality operator ==, this class notifies its[...]

I'm not sure to understand under what circumstances GraphQLClient.client.value would be updated by the framework.

/// A [ChangeNotifier] that holds a single value. /// /// When [value] is replaced with something that is not equal to the old /// value as evaluated by the equality operator ==, this class notifies its /// listeners.

Context: I'm trying to have my services access the client by creating it at the top of my build like the following and I just want to make sure GraphQLProvider wasn't going to update it's own client property;

   @override
  Widget build(BuildContext context) {
    final client = clientFor(
      uri: 'http://$host:3000/graphql',
      subscriptionUri: 'ws://$host:3000/graphql',
    );
    return MaterialApp(
        home: MultiProvider(
            providers: [ChangeNotifierProvider(create: (context) => UserModel(client))],
            child: ClientProvider(cli: client, child: MainScreen())
        ));
  }

I'm not very satisfied with Graphql.of since it appears to completely dissociate itself from the provider tree.

Note: It is quite unclear what the solution was here https://github.com/zino-app/graphql-flutter/issues/339

theGlenn avatar Jan 13 '21 11:01 theGlenn

I believe it is because the user may rebuild the client to change links or http endpoints, in which case Query widgets should be notified to refetch from the new configuration.

micimize avatar Jan 16 '21 20:01 micimize