graphql_flutter return LazyCacheMap, built_value deserializeWith JSON String, how to make them work together

Viewed 913

graphql_flutter return LazyCacheMap, built_value deserializeWith JSON String, how to make them work together.

  1. I use graphql_flutter to fetch data, and response give the result data as LazyCacheMap.
  2. And using built_value for data model & data serialization, but since deserializeWith working with JSON String.

What's the best way to work with them together ?

  • Should I just convert LazyCacheMap's data of to String and call deserializeWith ?
  • should I use other serialization pubs ?
1 Answers

First encode the response LazyCacheMap to JSON using the dart:convert package, then perform whatever operation you want.

import 'dart:convert';

GraphQLClient _client = graphQLConfiguration.clientToQuery();
QueryResult result = await _client.query(
  QueryOptions(
    documentNode: gql(GraphQlQueries.authenticateUser()),
  )
);

print(jsonEncode(result.data));

Worked for me.

Related