Skip to content

Commit

Permalink
GraphQL field support for consecutive uppercase letters. (#2552)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoozo authored Sep 9, 2024
1 parent 83cb54d commit e56e706
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/node-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Reuse the same temp dir when project is from IPFS (#2551)

### Fixed
- GraphQL field support for consecutive uppercase letters.

## [14.1.3] - 2024-08-30
### Fixed
- Fixed Corn filter (#2547)
Expand Down
12 changes: 12 additions & 0 deletions packages/node-core/src/indexer/store.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ describe('Store Service', () => {
expect(storeService.isIndexed('Transfer', 'accountToId')).toEqual(true);
expect(storeService.isIndexed('Transfer', 'accountToId2')).toEqual(false);
expect(storeService.isIndexed('Transfer2', 'accountToId')).toEqual(false);

expect(storeService.isIndexed('Transfer', 'AccountToId')).toEqual(true);
expect(storeService.isIndexed('Transfer', 'accountToID')).toEqual(true);
expect(storeService.isIndexed('Transfer', 'accountTo_ID')).toEqual(true);
expect(storeService.isIndexed('Transfer', 'accountTo_Id')).toEqual(true);
});

it('isIndexedHistorical support snake case', () => {
Expand Down Expand Up @@ -104,5 +109,12 @@ describe('Store Service', () => {
expect(storeService.isIndexedHistorical('Transfer2', 'accountToId')).toEqual(false);

expect(storeService.isIndexedHistorical('Transfer', 'not_index_id')).toEqual(false);

expect(storeService.isIndexedHistorical('Transfer', 'not_index_id')).toEqual(false);

expect(storeService.isIndexed('Transfer', 'AccountToId')).toEqual(true);
expect(storeService.isIndexed('Transfer', 'accountToID')).toEqual(true);
expect(storeService.isIndexed('Transfer', 'accountTo_ID')).toEqual(true);
expect(storeService.isIndexed('Transfer', 'accountTo_Id')).toEqual(true);
});
});
6 changes: 3 additions & 3 deletions packages/node-core/src/indexer/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from '../db';
import {getLogger} from '../logger';
import {exitWithError} from '../process';
import {camelCaseObjectKey} from '../utils';
import {camelCaseObjectKey, customCamelCaseGraphqlKey} from '../utils';
import {MetadataFactory, MetadataRepo, PoiFactory, PoiFactoryDeprecate, PoiRepo} from './entities';
import {Store} from './store';
import {CacheMetadataModel} from './storeCache';
Expand Down Expand Up @@ -440,7 +440,7 @@ group by
(upperFirst(camelCase(indexField.entityName)) === entity || indexField.entityName === entity) &&
// We add this because in some case upperFirst and camelCase will not match with entity name,
// see test entity name like `MinerIP`
camelCase(indexField.fieldName) === camelCase(field)
camelCase(indexField.fieldName) === customCamelCaseGraphqlKey(field)
) > -1
);
}
Expand All @@ -450,7 +450,7 @@ group by
this.modelIndexedFields.findIndex(
(indexField) =>
upperFirst(camelCase(indexField.entityName)) === entity &&
camelCase(indexField.fieldName) === camelCase(field) &&
camelCase(indexField.fieldName) === customCamelCaseGraphqlKey(field) &&
// With historical indexes are not unique
(this.historical || indexField.isUnique)
) > -1
Expand Down
8 changes: 8 additions & 0 deletions packages/node-core/src/utils/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ export function splitArrayByRatio(arr: number[], weights: number[]): number[][]
export function hasValue<T>(obj: T | undefined | null): obj is T {
return obj !== undefined && obj !== null;
}

export function customCamelCaseGraphqlKey(str: string) {
return str
.replace(/([a-z])([A-Z])/g, '$1_$2')
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
.toLowerCase()
.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
}

0 comments on commit e56e706

Please sign in to comment.