Closed manjeety87 closed 2 years ago
This is expected behaviour. The gql adds the typename which is used for normalisation.
This is expected behaviour. The gql adds the typename which is used for normalisation.
In postman when we fire query request it comes in json format which I can use but How would I get the data in proper json format so that I can map it down
What do you mean? The data is a map parsed from JSON.
If you need a json string, you can serialise it back as you'd normally do.
{typename: DummyStockData, title: nifty, subtitleData: 0.86(1.25%), subtitle: nse, titleData: 98.65, graphData: [{typename: GraphData, srno: 0, data: 50}, {typename: GraphData, srno: 1, data: 80}, {typename: GraphData, srno: 2, data: 90}, {typename: GraphData, srno: 3, data: 70}, {typename: GraphData, srno: 4, data: 100}, {typename: GraphData, srno: 5, data: 80}, {typename: GraphData, srno: 6, data: 70}, {typename: GraphData, srno: 7, data: 120}, {typename: GraphData, srno: 8, data: 100}, {__typename: GraphData, srno: 9, data: 140}]}
The output I want is in json format
{ DummyStockData: title: nifty, subtitleData: 0.86(1.25%), subtitle: nse, titleData: 98.65 graphData: [ {srno: 0, data: 50},{srno: 2, data: 90}, { srno: 3, data: 70}, { srno: 4, data: 100}, {srno: 5, data: 80}, { srno: 6, data: 70}, {srno: 7, data: 120}, {srno: 8, data: 100}, {srno: 9, data: 140} ] }
why there extra data like __typename is coming ? DummyStockData is a object in which graphData is array of objects
My Code : `class QueryExample extends StatelessWidget { final String getMission = r""" query MyQuery { getDummyStockData { title subtitleData subtitle titleData graphData { srno
data } } } """; const QueryExample({Key? key}) : super(key: key);
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("GraphlQL Client"), ), body: Query( options: QueryOptions( document: gql(getMission), ), builder: (QueryResult result, {VoidCallback? refetch, FetchMore? fetchMore}) { if (result.hasException) { return Text(result.exception.toString()); }
} } `
How can I change the query result to type dynamic to - `class SharesCardModel { final String title; final String subtitle; final String titleData; final String subtitleData; final List graphData;
SharesCardModel({
required this.title,
required this.subtitle,
required this.titleData,
required this.subtitleData,
required this.graphData,
});
}
class LineGraphData {
final int time;
final int shares;
LineGraphData(this.time, this.shares); }`