getGalleryById method

  1. @override
Future<Gallery> getGalleryById(
  1. String id
)
override

Implementation

@override
Future<Gallery> getGalleryById(String id) async {
  const query = r'''
    query FindGallery($id: ID!) {
      findGallery(id: $id) {
        id
        title
        date
        rating
        image_count
        details
      }
    }
  ''';

  final result = await client.query(
    QueryOptions(
      document: gql(query),
      variables: {'id': id},
    ),
  );

  if (result.hasException) throw result.exception!;
  final data = result.data?['findGallery'];
  if (data == null) throw Exception('Gallery not found');

  return Gallery.fromJson(data as Map<String, dynamic>);
}