Skip to content

Commit

Permalink
fix(compatibility): Rename aggregation keywords
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Possible breaking change aggregation keywords use underscore as prefix to prevent field clashes
  • Loading branch information
unlight committed May 19, 2021
1 parent 24aa0ae commit 83491c8
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 59 deletions.
10 changes: 5 additions & 5 deletions src/@generated/article/aggregate-article.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ export class AggregateArticleArgs {
skip?: number;

@Field(() => ArticleCountAggregateInput, { nullable: true })
count?: ArticleCountAggregateInput;
_count?: ArticleCountAggregateInput;

@Field(() => ArticleAvgAggregateInput, { nullable: true })
avg?: ArticleAvgAggregateInput;
_avg?: ArticleAvgAggregateInput;

@Field(() => ArticleSumAggregateInput, { nullable: true })
sum?: ArticleSumAggregateInput;
_sum?: ArticleSumAggregateInput;

@Field(() => ArticleMinAggregateInput, { nullable: true })
min?: ArticleMinAggregateInput;
_min?: ArticleMinAggregateInput;

@Field(() => ArticleMaxAggregateInput, { nullable: true })
max?: ArticleMaxAggregateInput;
_max?: ArticleMaxAggregateInput;
}
10 changes: 5 additions & 5 deletions src/@generated/article/group-by-article.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ export class GroupByArticleArgs {
skip?: number;

@Field(() => ArticleCountAggregateInput, { nullable: true })
count?: ArticleCountAggregateInput;
_count?: ArticleCountAggregateInput;

@Field(() => ArticleAvgAggregateInput, { nullable: true })
avg?: ArticleAvgAggregateInput;
_avg?: ArticleAvgAggregateInput;

@Field(() => ArticleSumAggregateInput, { nullable: true })
sum?: ArticleSumAggregateInput;
_sum?: ArticleSumAggregateInput;

@Field(() => ArticleMinAggregateInput, { nullable: true })
min?: ArticleMinAggregateInput;
_min?: ArticleMinAggregateInput;

@Field(() => ArticleMaxAggregateInput, { nullable: true })
max?: ArticleMaxAggregateInput;
_max?: ArticleMaxAggregateInput;
}
6 changes: 3 additions & 3 deletions src/@generated/comment/aggregate-comment.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class AggregateCommentArgs {
skip?: number;

@Field(() => CommentCountAggregateInput, { nullable: true })
count?: CommentCountAggregateInput;
_count?: CommentCountAggregateInput;

@Field(() => CommentMinAggregateInput, { nullable: true })
min?: CommentMinAggregateInput;
_min?: CommentMinAggregateInput;

@Field(() => CommentMaxAggregateInput, { nullable: true })
max?: CommentMaxAggregateInput;
_max?: CommentMaxAggregateInput;
}
6 changes: 3 additions & 3 deletions src/@generated/comment/group-by-comment.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class GroupByCommentArgs {
skip?: number;

@Field(() => CommentCountAggregateInput, { nullable: true })
count?: CommentCountAggregateInput;
_count?: CommentCountAggregateInput;

@Field(() => CommentMinAggregateInput, { nullable: true })
min?: CommentMinAggregateInput;
_min?: CommentMinAggregateInput;

@Field(() => CommentMaxAggregateInput, { nullable: true })
max?: CommentMaxAggregateInput;
_max?: CommentMaxAggregateInput;
}
10 changes: 5 additions & 5 deletions src/@generated/dummy/aggregate-dummy.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ export class AggregateDummyArgs {
skip?: number;

@Field(() => DummyCountAggregateInput, { nullable: true })
count?: DummyCountAggregateInput;
_count?: DummyCountAggregateInput;

@Field(() => DummyAvgAggregateInput, { nullable: true })
avg?: DummyAvgAggregateInput;
_avg?: DummyAvgAggregateInput;

@Field(() => DummySumAggregateInput, { nullable: true })
sum?: DummySumAggregateInput;
_sum?: DummySumAggregateInput;

@Field(() => DummyMinAggregateInput, { nullable: true })
min?: DummyMinAggregateInput;
_min?: DummyMinAggregateInput;

@Field(() => DummyMaxAggregateInput, { nullable: true })
max?: DummyMaxAggregateInput;
_max?: DummyMaxAggregateInput;
}
10 changes: 5 additions & 5 deletions src/@generated/dummy/group-by-dummy.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ export class GroupByDummyArgs {
skip?: number;

@Field(() => DummyCountAggregateInput, { nullable: true })
count?: DummyCountAggregateInput;
_count?: DummyCountAggregateInput;

@Field(() => DummyAvgAggregateInput, { nullable: true })
avg?: DummyAvgAggregateInput;
_avg?: DummyAvgAggregateInput;

@Field(() => DummySumAggregateInput, { nullable: true })
sum?: DummySumAggregateInput;
_sum?: DummySumAggregateInput;

@Field(() => DummyMinAggregateInput, { nullable: true })
min?: DummyMinAggregateInput;
_min?: DummyMinAggregateInput;

@Field(() => DummyMaxAggregateInput, { nullable: true })
max?: DummyMaxAggregateInput;
_max?: DummyMaxAggregateInput;
}
6 changes: 3 additions & 3 deletions src/@generated/tag/aggregate-tag.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class AggregateTagArgs {
skip?: number;

@Field(() => TagCountAggregateInput, { nullable: true })
count?: TagCountAggregateInput;
_count?: TagCountAggregateInput;

@Field(() => TagMinAggregateInput, { nullable: true })
min?: TagMinAggregateInput;
_min?: TagMinAggregateInput;

@Field(() => TagMaxAggregateInput, { nullable: true })
max?: TagMaxAggregateInput;
_max?: TagMaxAggregateInput;
}
6 changes: 3 additions & 3 deletions src/@generated/tag/group-by-tag.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class GroupByTagArgs {
skip?: number;

@Field(() => TagCountAggregateInput, { nullable: true })
count?: TagCountAggregateInput;
_count?: TagCountAggregateInput;

@Field(() => TagMinAggregateInput, { nullable: true })
min?: TagMinAggregateInput;
_min?: TagMinAggregateInput;

@Field(() => TagMaxAggregateInput, { nullable: true })
max?: TagMaxAggregateInput;
_max?: TagMaxAggregateInput;
}
10 changes: 5 additions & 5 deletions src/@generated/user/aggregate-user.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ export class AggregateUserArgs {
skip?: number;

@Field(() => UserCountAggregateInput, { nullable: true })
count?: UserCountAggregateInput;
_count?: UserCountAggregateInput;

@Field(() => UserAvgAggregateInput, { nullable: true })
avg?: UserAvgAggregateInput;
_avg?: UserAvgAggregateInput;

@Field(() => UserSumAggregateInput, { nullable: true })
sum?: UserSumAggregateInput;
_sum?: UserSumAggregateInput;

@Field(() => UserMinAggregateInput, { nullable: true })
min?: UserMinAggregateInput;
_min?: UserMinAggregateInput;

@Field(() => UserMaxAggregateInput, { nullable: true })
max?: UserMaxAggregateInput;
_max?: UserMaxAggregateInput;
}
10 changes: 5 additions & 5 deletions src/@generated/user/group-by-user.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ export class GroupByUserArgs {
skip?: number;

@Field(() => UserCountAggregateInput, { nullable: true })
count?: UserCountAggregateInput;
_count?: UserCountAggregateInput;

@Field(() => UserAvgAggregateInput, { nullable: true })
avg?: UserAvgAggregateInput;
_avg?: UserAvgAggregateInput;

@Field(() => UserSumAggregateInput, { nullable: true })
sum?: UserSumAggregateInput;
_sum?: UserSumAggregateInput;

@Field(() => UserMinAggregateInput, { nullable: true })
min?: UserMinAggregateInput;
_min?: UserMinAggregateInput;

@Field(() => UserMaxAggregateInput, { nullable: true })
max?: UserMaxAggregateInput;
_max?: UserMaxAggregateInput;
}
5 changes: 2 additions & 3 deletions src/handlers/args-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export function argsType(field: SchemaField, args: EventArguments) {
};

if (
// TODO: Figure out how to improve this (solve mutation)
!field.args.some(x => x.name === 'count') &&
!field.args.some(x => x.name === '_count') &&
[`Aggregate${modelName}Args`, `GroupBy${modelName}Args`].includes(
inputType.name,
)
Expand All @@ -42,7 +41,7 @@ export function argsType(field: SchemaField, args: EventArguments) {
}

inputType.fields.push({
name: name.toLowerCase(),
name: `_${name.toLowerCase()}`,
isRequired: false,
isNullable: true,
inputTypes: [
Expand Down
20 changes: 6 additions & 14 deletions src/test/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ describe('model with one id int', () => {

describe('aggregate user args', () => {
before(() => {
sourceFile = project.getSourceFile(s =>
s.getFilePath().endsWith('aggregate-user.args.ts'),
)!;
setSourceFile('aggregate-user.args.ts');
classFile = sourceFile.getClass(() => true)!;
});

Expand All @@ -240,32 +238,26 @@ describe('model with one id int', () => {
});

it('count', () => {
const count = getPropertyStructure(sourceFile, 'count');
expect(count?.type).toEqual('UserCountAggregateInput');
expect(p('_count')?.type).toEqual('UserCountAggregateInput');
});

it('sum', () => {
const sum = getPropertyStructure(sourceFile, 'sum');
expect(sum?.type).toEqual('UserSumAggregateInput');
expect(p('_sum')?.type).toEqual('UserSumAggregateInput');
});

it('min', () => {
const min = getPropertyStructure(sourceFile, 'min');
expect(min?.type).toEqual('UserMinAggregateInput');
expect(p('_min')?.type).toEqual('UserMinAggregateInput');
});

it('max', () => {
const max = getPropertyStructure(sourceFile, 'max');
expect(max?.type).toEqual('UserMaxAggregateInput');
expect(p('_max')?.type).toEqual('UserMaxAggregateInput');
});
});

describe('user count aggregate input', () => {
let id: PropertyDeclarationStructure;
before(() => {
sourceFile = project.getSourceFile(s =>
s.getFilePath().endsWith('user-count-aggregate.input.ts'),
)!;
setSourceFile('user-count-aggregate.input.ts');
id = getPropertyStructure(sourceFile, 'id')!;
});

Expand Down

0 comments on commit 83491c8

Please sign in to comment.