Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum Support #32

Open
Arpit1496 opened this issue Oct 15, 2023 · 3 comments
Open

Enum Support #32

Arpit1496 opened this issue Oct 15, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@Arpit1496
Copy link

Arpit1496 commented Oct 15, 2023

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,
      },
    );
  }
}
@raddevon raddevon added the enhancement New feature or request label Nov 14, 2023
@Arpit1496
Copy link
Author

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.

@raddevon
Copy link
Contributor

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

@Arpit1496
Copy link
Author

Any update on this ?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants