edgedb-dart icon indicating copy to clipboard operation
edgedb-dart copied to clipboard

Enum Support

Open Arpit1496 opened this issue 1 year ago • 3 comments

Describe the bug The edgedb generator does not generated enum types defined in schema. It treats enum as String and creates fields of classes with String as datatype.

Reproduction Schema:

module default {
    scalar type Status extending enum<'UNSPECIFIED','PENDING','FAILED','PAID'>;
    type Locations {
        required is_active: bool;
        link geo_location: LatLong {
            constraint exclusive;
        }
        required last_activity: datetime;
        required payment_status: Status;
    }

    type LatLong {
        required x_coord: float32;
        required y_coord: float32;
        single link location := .<geo_location[is Locations]
    }
}

Query:

select default::Locations {
  id,
  is_active,
  last_activity,
  payment_status,
  geo_location: {
    id,
    x_coord,
    y_coord
  }
  order by .x_coord
}
filter .payment_status ?= <Status>$payment_status and .is_active ?= <std::bool>$active and .last_activity <= <std::datetime>$last_activity
order by .last_activity empty last
offset <std::int64>$offset
limit <std::int64>$page_count

Expected behavior The output of PAYMENT status in data classes generated should have Enum as Data type. Instead, String is generated.

Generated .dart file for above query:

// AUTOGENERATED by 'edgeql_codegen' builder
// To re-generate use `dart run build_runner`

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:edgedb/src/codecs/codecs.dart' as _i1;
import 'package:edgedb/src/client.dart' as _i2;
import 'package:edgedb/src/primitives/types.dart' as _i3;

class Read_locations_geo_location {
  Read_locations_geo_location._fromMap(Map<String, dynamic> map)
      : id = map['id'],
        x_coord = map['x_coord'],
        y_coord = map['y_coord'];

  final String id;

  final double x_coord;

  final double y_coord;

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'x_coord': x_coord,
      'y_coord': y_coord,
    };
  }

  Map<String, dynamic> toJson() {
    return toMap();
  }
}

class Read_locations {
  Read_locations._fromMap(Map<String, dynamic> map)
      : id = map['id'],
        is_active = map['is_active'],
        last_activity = map['last_activity'],
        payment_status = map['payment_status'],
        geo_location = map['geo_location'];

  final String id;

  final bool is_active;

  final DateTime last_activity;

  final String payment_status;

  final Read_locations_geo_location? geo_location;

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'is_active': is_active,
      'last_activity': last_activity,
      'payment_status': payment_status,
      'geo_location': geo_location,
    };
  }

  Map<String, dynamic> toJson() {
    return toMap();
  }
}

const _query = '''select default::Locations {
  id,
  is_active,
  last_activity,
  payment_status,
  geo_location: {
    id,
    x_coord,
    y_coord
  }
  order by .x_coord
}
filter .payment_status ?= <Status>\$payment_status and .is_active ?= <std::bool>\$active and .last_activity <= <std::datetime>\$last_activity
order by .last_activity empty last
offset <std::int64>\$offset
limit <std::int64>\$page_count''';
final _outCodec = _i1.ObjectCodec(
  '1952a3ebaf635295af9f38e6815fceb9',
  [
    _i1.scalarCodecs['00000000000000000000000000000100']!,
    _i1.scalarCodecs['00000000000000000000000000000109']!,
    _i1.scalarCodecs['0000000000000000000000000000010a']!,
    _i1.EnumCodec('9dfc25ea6a7111eeadb25f34ee81bf4e'),
    _i1.ObjectCodec(
      '1304e864f94b59f3b8d7eeac17c832e7',
      [
        _i1.scalarCodecs['00000000000000000000000000000100']!,
        _i1.scalarCodecs['00000000000000000000000000000106']!,
        _i1.scalarCodecs['00000000000000000000000000000106']!,
      ],
      [
        'id',
        'x_coord',
        'y_coord',
      ],
      [
        65,
        65,
        65,
      ],
      returnType: Read_locations_geo_location._fromMap,
    ),
  ],
  [
    'id',
    'is_active',
    'last_activity',
    'payment_status',
    'geo_location',
  ],
  [
    65,
    65,
    65,
    65,
    111,
  ],
  returnType: Read_locations._fromMap,
);
final _inCodec = _i1.ObjectCodec(
  '54ce40b05e635a6683a9c23c89dda21d',
  [
    _i1.EnumCodec('9dfc25ea6a7111eeadb25f34ee81bf4e'),
    _i1.scalarCodecs['00000000000000000000000000000109']!,
    _i1.scalarCodecs['0000000000000000000000000000010a']!,
    _i1.scalarCodecs['00000000000000000000000000000105']!,
    _i1.scalarCodecs['00000000000000000000000000000105']!,
  ],
  [
    'payment_status',
    'active',
    'last_activity',
    'offset',
    'page_count',
  ],
  [
    65,
    65,
    65,
    65,
    65,
  ],
);

extension Read_locationsExtension on _i2.Executor {
  Future<List<Read_locations>> read_locations({
    required String payment_status,
    required bool active,
    required DateTime last_activity,
    required int offset,
    required int page_count,
  }) async {
    return await _i2.executeWithCodec<Read_locations>(
      this,
      'read_locations',
      _outCodec,
      _inCodec,
      _i3.Cardinality.many,
      _query,
      <String, dynamic>{
        'payment_status': payment_status,
        'active': active,
        'last_activity': last_activity,
        'offset': offset,
        'page_count': page_count,
      },
    );
  }
}

Arpit1496 avatar Oct 15 '23 15:10 Arpit1496

Hi team, Any update on this ? Also if possible, do let me know if I can help. I cannot quite understand codec generation. But you can suggest some good head starts.

Arpit1496 avatar Dec 11 '23 22:12 Arpit1496

@Arpit1496 Actively looking into this. We'll report back!

raddevon avatar Dec 12 '23 12:12 raddevon

Any update on this ?

This feels like dart community is lagging behind other languages. Can I provide any support ?

Arpit1496 avatar Aug 05 '24 07:08 Arpit1496