vyuh-tech / vyuh

Build Modular, Scalable, CMS-driven Flutter Apps
https://vyuh.tech
Other
77 stars 11 forks source link

[sanity_client] Cannot perform queries #9

Closed muccy closed 3 months ago

muccy commented 3 months ago

I'm using sanity_client: ^1.2.1 but I cannot complete a basic query like:

*[_type == "event"]{
  name,
  date,
  venue->{
    name
  },
  headline->{
    name
  },
  image,
  tickets
}

The reported error is:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>?' in type cast
#0      _$ServerResponseFromJson (package:sanity_client/response_types.g.dart:17:30)
#1      new ServerResponse.fromJson (package:sanity_client/response_types.dart:51:7)
#2      SanityClient._getQueryResult (package:sanity_client/client.dart:145:47)
#3      SanityClient.fetch (package:sanity_client/client.dart:111:12)
<asynchronous suspension>
#4      _HomeState.build.<anonymous closure> (package:flutter_sanity_test/src/home.dart:57:34)

Looking at the JSON Serializable generated code I see:

ServerResponse _$ServerResponseFromJson(Map<String, dynamic> json) =>
    ServerResponse(
      result: json['result'] as Map<String, dynamic>?,
      ms: json['ms'] as int,
      query: json['query'] as String,
    );

But json["result"] isn't a Map, but a List.

I could think about a fix, but I don't know if you set Map type for a reason (I'm totally unexperienced with Sanity.io and GROQ)

pavanpodila commented 3 months ago

Yup looks like a bug in the client where the type has been set to a Map instead of dynamic.

pavanpodila commented 3 months ago

This is now fixed in the latest version: ^1.2.2, with a test as well. Please update and try again @muccy. I'll close it once you verify.

pavanpodila commented 3 months ago

Closing it for now ... pls reopen if this is still an issue