Skip to content

Commit

Permalink
runner query support @subql/query-subgraph option (#2561)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoozo authored Sep 24, 2024
1 parent 2c67a93 commit 5d71d13
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- `Runner.query` support `@subql/query-subgraph` option

## [5.1.2] - 2024-09-09
### Changed
- Expose CID on IPFS Reader (#2551)
Expand Down
49 changes: 48 additions & 1 deletion packages/common/src/project/versioned/v1_0_0/model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {IProjectNetworkConfig} from '@subql/types-core';
import {plainToClass} from 'class-transformer';
import {validateSync} from 'class-validator';
import {CommonProjectNetworkV1_0_0} from './models';
import {CommonProjectNetworkV1_0_0, CommonRunnerSpecsImpl} from './models';

describe('Validating base v1_0_0 model', () => {
it('correctly validates the various endpoint structures in a network config', () => {
Expand Down Expand Up @@ -72,4 +72,51 @@ describe('Validating base v1_0_0 model', () => {
expect(() => validate(bad3)).toThrow();
expect(() => validate(bad4)).toThrow();
});

it('validates manifest Runner', () => {
function validate(raw: unknown) {
const projectManifest = plainToClass<CommonRunnerSpecsImpl, unknown>(CommonRunnerSpecsImpl, raw);
const errors = validateSync(projectManifest, {whitelist: true});

if (errors.length) {
throw new Error(errors.map((e) => e.value).join('\n'));
}
}

const normalRunner: unknown = {
node: {
name: '@subql/node',
version: '>=3.0.1',
},
query: {
name: '@subql/query',
version: '*',
},
};

const notExistQueryRunner: unknown = {
node: {
name: '@subql/node',
version: '>=3.0.1',
},
query: {
name: '@subql/not-exist',
version: '*',
},
};
const subgraphQueryRunner: unknown = {
node: {
name: '@subql/node',
version: '>=3.0.1',
},
query: {
name: '@subql/query-subgraph',
version: '*',
},
};

expect(() => validate(normalRunner)).not.toThrow();
expect(() => validate(notExistQueryRunner)).toThrow();
expect(() => validate(subgraphQueryRunner)).not.toThrow();
});
});
3 changes: 2 additions & 1 deletion packages/common/src/project/versioned/v1_0_0/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import {
Allow,
ValidateIf,
IsPositive,
IsIn,
} from 'class-validator';
import {IsNetworkEndpoint, SemverVersionValidator} from '../../utils';
import {FileType} from '../base';

export class RunnerQueryBaseModel implements QuerySpec {
@Equals('@subql/query')
@IsIn(['@subql/query', '@subql/query-subgraph'])
name!: string;
@IsString()
@Validate(SemverVersionValidator)
Expand Down

0 comments on commit 5d71d13

Please sign in to comment.