Skip to content

Commit

Permalink
fix(generator): Json field short input type selection
Browse files Browse the repository at this point in the history
Refs: #209 #216
  • Loading branch information
medz committed May 23, 2023
1 parent bf41020 commit dd904d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions bin/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,31 @@ extension InputObjectTypesGenerator on PrismaDartClientGenerator {

/// Build field type
code.Reference _buildFieldType(dmmf.SchemaArg field) {
final types = field.inputTypes;
/// TODO: bug https://github.com/odroe/prisma-dart/issues/209
withoutJsonValueInput(String name) {
if (name == 'NullableJsonNullValueInput') return false;
if (name == 'JsonNullValueInput') return false;

return true;
}

final types = field.inputTypes.where((element) => element.type.when<bool>(
string: withoutJsonValueInput,
input: (input) => withoutJsonValueInput(input.name),
enum_: (enum_) => withoutJsonValueInput(enum_.name),
));

// If the types is a single type, return it.
if (types.length == 1) {
final type = field.inputTypes.first.type.when<String>(
final type = types.first.type.when<String>(
string: (value) => value,
input: (type) => type.name,
enum_: (type) => type.name,
);

return scalar(
type,
location: field.inputTypes.first.location,
location: types.first.location,
isNullable: !field.isRequired,
isList: field.inputTypes.first.isList,
);
Expand Down
2 changes: 1 addition & 1 deletion bin/src/scalars.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final Map<String, Reference> scalarReferences = {
'int': refer('int'),
'bigint': refer('BigInt'),
'boolean': refer('bool'),
'json': refer('dynamic'),
'json': refer('Object'),
'bytes': TypeReference((TypeReferenceBuilder updates) {
updates.symbol = 'List';
updates.types.add(Reference('int'));
Expand Down

1 comment on commit dd904d7

@vercel
Copy link

@vercel vercel bot commented on dd904d7 May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.