Skip to content

Commit

Permalink
fix: Fixed group by query
Browse files Browse the repository at this point in the history
  • Loading branch information
Seven Du committed Feb 17, 2023
1 parent a1b3741 commit 4524256
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions bin/generator/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,27 @@ extension ModelFluentGenerator on Generator {
.property('map')
.call([localMapCompiler]);

final fieldsExpression =
code.Expression fieldsExpression =
(fields == null || fields.isEmpty) ? modelScalarFields : localFields;

if (field.name.toLowerCase().startsWith('groupby')) {
final enumMapCompiler = code.Method((updates) {
updates.requiredParameters.add(code.Parameter((updates) {
updates.name = 'e';
}));
updates.body =
code.refer('GraphQLField', packages.graphql).newInstance([
code
.refer('e')
.property('originalName')
.ifNullThen(code.refer('e').property('name'))
]).code;
updates.lambda = true;
}).closure;
fieldsExpression =
code.refer('by').property('map').call([enumMapCompiler]);
}

expressions.add(code.declareFinal('fields').assign(fieldsExpression));

code.Reference type = code.refer('Map');
Expand Down Expand Up @@ -847,17 +865,21 @@ extension ModelFluentGenerator on Generator {
}));
updates.lambda = true;

final compiler = code.refer('compiler').call([code.refer('json')]);
final call = field.outputType.isList
? code.refer('json').property('cast').call([])
: code.refer('json');

final compiler = code.refer('compiler').call([call]);
final thrown = code.refer('Exception').newInstance([
code.literalString('Unable to parse response'),
]).thrown;

updates.body = code
.refer('json')
.isA(type)
.conditional(compiler,
_isOperationReturnTypeNullable(field) ? code.literalNull : thrown)
.code;
final other =
_isOperationReturnTypeNullable(field) ? code.literalNull : thrown;
final $type = field.outputType.isList ? code.refer('Iterable') : type;

updates.body =
code.refer('json').isA($type).conditional(compiler, other).code;
});

final returns = code
Expand Down

0 comments on commit 4524256

Please sign in to comment.