I just upgrade graphql_flutter version "3.1.0" to "5.0.0-nullsafety.5".
IDE has an exception: "The method 'OptimisticCache' isn't defined for the type 'GraphQLService'."
My code:
ValueNotifier(
GraphQLClient(
cache: OptimisticCache(dataIdFromObject: typenameDataIdFromObject),
link: link,
defaultPolicies: DefaultPolicies(
watchQuery: Policies(
fetch: FetchPolicy.noCache,
),
query: Policies(
fetch: FetchPolicy.noCache,
),
mutate: Policies(
fetch: FetchPolicy.noCache,
),
),
),
)
How to fix it?
final GraphQLCache cache = GraphQLCache(
dataIdFromObject: uuidFromObject,
);
Related
I am new here and i searched a lot but got no any results. how to get require below format in retrieving data from sqflite in Flutter. i want to create page like products with category within sub category but getting data from sqflite local database.
final List<DataList> data = <DataList>[
DataList(
'Mobiles',
<DataList>[
DataList(
'MI',
<DataList>[
DataList('Redmi Note 9'),
DataList('Redmi Note 10'),
DataList('Mi 10i 5G'),
],
),
DataList('Samsung'),
DataList('Apple'),
],
),
DataList(
'Laptops',
<DataList>[
DataList('Dell'),
DataList('HP'),
],
),
DataList(
'Appliances',
<DataList>[
DataList('Washing Machine'),
DataList('AC'),
DataList(
'Home Appliances',
<DataList>[
DataList('Water Purifier'),
DataList('Inverter'),
DataList('Vacuum Cleaner'),
],
),
],
),
];
i was trying Future list to getting data from sqflite
My code to create a dynamic link is as follows:
Future<Uri?> createDynamicLinkForThisSite(String userUID, String? siteUID) async {
if (siteUID == null || siteUID.isEmpty) return null;
final DynamicLinkParameters parameters = DynamicLinkParameters(
uriPrefix: 'https://s--**-er.page.link', // This should also be updated in Android Manifest.com under intent filters
link: Uri.parse('https://sna***per.com/?ownerID=$userUID&siteID=$siteUID'),
androidParameters: AndroidParameters(
fallbackUrl: Uri.parse('https://sna***per.com'),
packageName: 'uk.co.e*l**a.sna**er',
minimumVersion: 1,
),
iosParameters: IOSParameters(
bundleId: 'uk.co.e--n.sn--er',
fallbackUrl: Uri.parse('https://sn--er.com'),
ipadFallbackUrl: Uri.parse('https://sn--er.com'),
ipadBundleId: 'uk.co.ee--an.sn--er',
minimumVersion: '0',
appStoreId: '14--66',
),
navigationInfoParameters: const NavigationInfoParameters(
forcedRedirectEnabled: false,
),
//dynamicLinkParametersOptions: DynamicLinkParametersOptions(
// shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
//),
);
var dynamicLinks = FirebaseDynamicLinks.instance;
return (await dynamicLinks.buildShortLink(parameters)).shortUrl;
}
I have 'Associated Dynamic Links active in developer account and also in Xcode.
When I click on the dynamic link on an iOS device I get the following screen:
The clicking on the button gives me the fallback url:
This works fine on android. What am I doing wrong here please?
I am new to flutter development but I have good experience in nodejs and graphql. I am trying to consume the subscription widget of graphql-flutter and update the changes. but the connection is not being established. But I could use the query and Mutation widget and get the results. The examples provided by the graphql-flutter team is 2 years old and same with https://hasura.io/ documents. Can someone help me providing the latest examples or samples.
graphql-flutter:^5.0.0
If additional infos needed please comment below.
Thanks in advance
I made a class that I use with graphql but it'll be able to work with graphql-flutter but passing the client to
return GraphQLProvider(
client: Services().graphQL.client, // just how I have my services set up
child: MaterialApp(
title: 'Flutter Demo',
...
),
);
class:
class GraphQL {
static final HttpLink _httpLink = HttpLink(environment[envMode]!['server']);
static WebSocketLink _wsLink(String token) => WebSocketLink(
environment[envMode]!['webSocket'],
config: SocketClientConfig(
inactivityTimeout: const Duration(hours: 1),
initialPayload: {
'Authorization': 'Bearer $token',
},
),
);
Link _splitLink(String token) => Link.split(
(request) => request.isSubscription,
_wsLink(token),
_httpLink,
);
GraphQLClient client(String token) {
return GraphQLClient(
link: AuthLink(getToken: () async => 'Bearer $token')
.concat(_splitLink(token)),
cache: GraphQLCache(
store: HiveStore(),
),
);
}
Future<void> initHive() async {
return await initHiveForFlutter();
}
}
The environment and envMode come from a config file that has gets its data from an env file to keep manage env and secrets.
I'm trying to implement graphQl Flutter package in my app.
https://github.com/zino-app/graphql-flutter
Everything works well, but I have some issues with cache.
If we ran example from this package https://github.com/zino-app/graphql-flutter/tree/master/packages/graphql_flutter/example we can see that cache doesn't work.
In my app I also can't increase speed, it always get data online.
The code from this example
class GraphQLWidgetScreen extends StatelessWidget {
const GraphQLWidgetScreen() : super();
#override
Widget build(BuildContext context) {
final HttpLink httpLink = HttpLink(
uri: 'https://api.github.com/graphql',
);
final AuthLink authLink = AuthLink(
// ignore: undefined_identifier
getToken: () async => 'Bearer $YOUR_TOKEN',
);
Link link = authLink.concat(httpLink);
if (ENABLE_WEBSOCKETS) {
final WebSocketLink websocketLink = WebSocketLink(
url: 'ws://localhost:8080/ws/graphql',
config: SocketClientConfig(
autoReconnect: true, inactivityTimeout: Duration(seconds: 15)),
);
link = link.concat(websocketLink);
}
final ValueNotifier<GraphQLClient> client = ValueNotifier<GraphQLClient>(
GraphQLClient(
cache: OptimisticCache(
dataIdFromObject: typenameDataIdFromObject,
),
link: link,
),
);
return GraphQLProvider(
client: client,
child: const CacheProvider(
child: MyHomePage(title: 'GraphQL Widget'),
),
);
}
}
Animation that shows that cache doesn't work
So, the question is - what is the right way to implement cache and how check it works.
Thank you!
The examples are meant to be standalone - as such they use separate clients and caches. The consequence of this is that it is re-instantiated every mount. In other words, every time you navigates to the example's route, you get a new cache, so you can't see the caching effects. For a more substantial example where you can see if the cache is working, see the starwars example (related github discussion)
I am using graphql_flutter package in my app. This is the code for my client:
HttpLink httpLink = HttpLink(
uri: 'https://*******/graphql',
);
WebSocketLink webSocketLink = WebSocketLink(
url: "wss://*******/graphql/websocket/",
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: Duration(seconds: 30),
),
);
AuthLink authLink = AuthLink(
getToken: ()async{
print(await SharedPreferencesHelper.getAuthenticationToken());
return "Bearer ${await SharedPreferencesHelper.getAuthenticationToken()}";
}
);
Link link = authLink.concat(httpLink);
link = link.concat(webSocketLink);
client = ValueNotifier(
GraphQLClient(
cache: InMemoryCache(),
link: link,
),
);
However whenever I create a subscription like this:
client.value.subscribe(Operation(
document: Subscriptions.chatMessageReceived,
variables: {
"receiverId": *******
}
)).listen((fetchResult){
print(fetchResult.data);
});
I get this log in repetition:
Connecting to websocket: wss://******/graphql/websocket/... flutter:
Connected to websocket. flutter: Disconnected from websocket. flutter:
Scheduling to connect in 5 seconds... flutter: Connecting to
websocket: wss://******/graphql/websocket/...
Even though everything works fine in graphql playground. What can it be?
this is because of inactivityTimeout: Duration(seconds: 30), in WebSocketLink config
you can increase the Duration to prevent it from auto disconnecting.