From ca3c1badd8d8406a55cee30debaa09de452da816 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 15 Feb 2021 11:55:15 +0000 Subject: [PATCH 01/13] fixing spelling mistake, to -> two --- docs/mappings/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/mappings/README.md b/docs/mappings/README.md index d8b63879c..6e7ae1f92 100644 --- a/docs/mappings/README.md +++ b/docs/mappings/README.md @@ -47,7 +47,7 @@ and this is where all the auto-generated classes live by default. Next, the body of the handler transforms the event parameters and extrinsic arguments into the properties of the entity. There is currently no way to enforce type safety here and one should instead inspect the event parameters and extrinsics for the event in question. In the example above, we can consult the Kusama [explorer](https://kusama.subscan.io/extrinsic/0x1bba67ddb62117fc64710e35b6ccbef64d4df528d78310ccca725137e75823d4?event=2022835-5) and check that * `ProposalIndex` is a single named param of `treasury.Proposed` event -* The extrinsic has to arguments: `value` and `beneficiary`, propagated to the entity in a straightforward fashion. +* The extrinsic has two arguments: `value` and `beneficiary`, propagated to the entity in a straightforward fashion. Type-safe mappings and runtime upgrades will be supported in future releases of Hydra. From c14ccb74b18fe75366ed62b0904af8dee188e5d0 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 15 Feb 2021 12:03:20 +0000 Subject: [PATCH 02/13] adding windows alternative command --- docs/schema-spec/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/schema-spec/README.md b/docs/schema-spec/README.md index 088a633f1..547fce261 100644 --- a/docs/schema-spec/README.md +++ b/docs/schema-spec/README.md @@ -14,3 +14,10 @@ Hydra input schema is a dialect of the GraphQL schema definition language enrich $ hydra-cli preview && cat apipreview.graphql ``` +In windows, you should run: + +```text +$ hydra-cli preview && type apipreview.graphql +``` + + From 5a42cbc1202730efc34b716f6d649e19a89296e5 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 15 Feb 2021 12:08:22 +0000 Subject: [PATCH 03/13] grammar fix --- docs/schema-spec/the-query-goodies.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/schema-spec/the-query-goodies.md b/docs/schema-spec/the-query-goodies.md index 70a6fd80b..6a62cbb6d 100644 --- a/docs/schema-spec/the-query-goodies.md +++ b/docs/schema-spec/the-query-goodies.md @@ -8,7 +8,7 @@ description: >- ## Filtering -All the scalar entity types enjoy first-class support in the output schema when it comes to filtering. The standard is known as [OpenCRUD](https://www.opencrud.org/) and dictates who filtering should look like depending on the field type. For example, if the input schema defines the following type: +All the scalar entity types enjoy first-class support in the output schema when it comes to filtering. The standard is known as [OpenCRUD](https://www.opencrud.org/) and dictates what the filtering should look like depending on the field type. For example, if the input schema defines the following type: ```graphql type Person @entity { From 6e8f08ec120ddeb5caecdf9470839dae60931666 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 15 Feb 2021 12:11:20 +0000 Subject: [PATCH 04/13] grammar fix in ordering section --- docs/schema-spec/the-query-goodies.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/schema-spec/the-query-goodies.md b/docs/schema-spec/the-query-goodies.md index 6a62cbb6d..1a5fe7f9d 100644 --- a/docs/schema-spec/the-query-goodies.md +++ b/docs/schema-spec/the-query-goodies.md @@ -45,7 +45,7 @@ query { ## Ordering -The results can also be ordered by any property with natural ordering. `_DESC`an `_ASC` suffixes indicate the direction: +The results can also be ordered by any property with natural ordering. The `_DESC`and `_ASC` suffixes indicate the direction: ```graphql query { From ccf7ef10f151f220e4ac17a4d86bae73847300b7 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 15 Feb 2021 12:16:04 +0000 Subject: [PATCH 05/13] change spelling, live -> life --- docs/schema-spec/entities.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/schema-spec/entities.md b/docs/schema-spec/entities.md index 46ce36b20..deba79cca 100644 --- a/docs/schema-spec/entities.md +++ b/docs/schema-spec/entities.md @@ -42,7 +42,7 @@ type Person @entity { name: String! married: Boolean age: Int - "one person, one account, one live" + "one person, one account, one life" account: Bytes! @unique salary: BigInt interests: [String] From 5ad7dec015e17236d6688ba0a549fc9263bb6f23 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 15 Feb 2021 12:18:07 +0000 Subject: [PATCH 06/13] fixing enum code example --- docs/schema-spec/enums.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/schema-spec/enums.md b/docs/schema-spec/enums.md index 1f1daf88b..1b6f3f895 100644 --- a/docs/schema-spec/enums.md +++ b/docs/schema-spec/enums.md @@ -3,7 +3,7 @@ Enums are natively supported as described the GraphQL schema [spec](https://spec.graphql.org/June2018/#sec-Enums). Here is an illustrative example: ```text -enum { +enum ProposalStatus { NONE REJECTED APPROVED From 6e10203d65e00f034c009f426b8986883a23775f Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 15 Feb 2021 12:27:03 +0000 Subject: [PATCH 07/13] fixing spelling in example code output, highligt -> highlight --- docs/schema-spec/full-text-queries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/schema-spec/full-text-queries.md b/docs/schema-spec/full-text-queries.md index e8a427586..11356eacd 100644 --- a/docs/schema-spec/full-text-queries.md +++ b/docs/schema-spec/full-text-queries.md @@ -25,7 +25,7 @@ The generated output schema will define the required output type and the query: type SearchResult { item: Post | Comment, rank: number, - highligt: String + highlight: String } type Query { From f350575cb44f1371066c1124b1300a08c4a7a468 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 15 Feb 2021 12:38:43 +0000 Subject: [PATCH 08/13] Adding windows alternative to alias command --- docs/install-hydra.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/install-hydra.md b/docs/install-hydra.md index b71422279..5484b0d0e 100644 --- a/docs/install-hydra.md +++ b/docs/install-hydra.md @@ -49,5 +49,11 @@ It may be convenient to create an alias for quick access to `hydra-cli` e.g. ```text alias hydra-cli='npx @dzlzv/hydra-cli' ``` + +Or on Windows you can use: + +```text +doskey hydra-cli=npx @dzlzv/hydra-cli +``` {% endhint %} From 5b9d74510cd02a37f887e6f878ff9584ee319e0e Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Tue, 16 Feb 2021 15:09:45 +0000 Subject: [PATCH 09/13] correcting spacing --- docs/schema-spec/the-query-goodies.md | 2 +- yarn.lock | 42 ++++----------------------- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/docs/schema-spec/the-query-goodies.md b/docs/schema-spec/the-query-goodies.md index 1a5fe7f9d..33cfed405 100644 --- a/docs/schema-spec/the-query-goodies.md +++ b/docs/schema-spec/the-query-goodies.md @@ -45,7 +45,7 @@ query { ## Ordering -The results can also be ordered by any property with natural ordering. The `_DESC`and `_ASC` suffixes indicate the direction: +The results can also be ordered by any property with natural ordering. The `_DESC` and `_ASC` suffixes indicate the direction: ```graphql query { diff --git a/yarn.lock b/yarn.lock index 23c34c1e3..21b7cb81b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3647,11 +3647,6 @@ commander@^4.0.0: resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068" integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA== -commander@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae" - integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg== - commander@^6.2.0: version "6.2.1" resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" @@ -4921,7 +4916,7 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" -figlet@^1.1.1, figlet@^1.4.0: +figlet@^1.1.1: version "1.5.0" resolved "https://registry.yarnpkg.com/figlet/-/figlet-1.5.0.tgz#2db4d00a584e5155a96080632db919213c3e003c" integrity sha512-ZQJM4aifMpz6H19AW1VqvZ7l4pOE9p7i/3LyxgO2kp+PO/VcDYNqIHEMtkccqIhTXMKci4kjueJr/iCQEaT/Ww== @@ -7820,7 +7815,7 @@ log-update@^4.0.0: slice-ansi "^4.0.0" wrap-ansi "^6.2.0" -log4js@^6.2.1, log4js@^6.3.0: +log4js@^6.3.0: version "6.3.0" resolved "https://registry.yarnpkg.com/log4js/-/log4js-6.3.0.tgz#10dfafbb434351a3e30277a00b9879446f715bcb" integrity sha512-Mc8jNuSFImQUIateBFwdOQcmC6Q5maU0VVvdC2R6XMb66/VnT+7WS4D/0EeNMZu1YODmJe5NIn2XftCzEocUgw== @@ -9022,14 +9017,6 @@ path-type@^4.0.0: resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -path@^0.12.7: - version "0.12.7" - resolved "https://registry.yarnpkg.com/path/-/path-0.12.7.tgz#d4dc2a506c4ce2197eb481ebfcd5b36c0140b10f" - integrity sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8= - dependencies: - process "^0.11.1" - util "^0.10.3" - pathval@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.1.tgz#8534e77a77ce7ac5a2512ea21e0fdb8fcf6c3d8d" @@ -9133,7 +9120,7 @@ pg@^7.12.1: pgpass "1.x" semver "4.3.2" -pg@^8.0.3, pg@^8.3.2: +pg@^8.3.2: version "8.5.1" resolved "https://registry.yarnpkg.com/pg/-/pg-8.5.1.tgz#34dcb15f6db4a29c702bf5031ef2e1e25a06a120" integrity sha512-9wm3yX9lCfjvA98ybCyw2pADUivyNWT/yIP4ZcDVpMN0og70BUWYEGXPCTAQdGTAqnytfRADb7NERrY1qxhIqw== @@ -9338,11 +9325,6 @@ process-on-spawn@^1.0.0: dependencies: fromentries "^1.2.0" -process@^0.11.1: - version "0.11.10" - resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" - integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI= - progress@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" @@ -10834,7 +10816,7 @@ ts-mockito@^2.6.1: dependencies: lodash "^4.17.5" -ts-node-dev@^1.0.0-pre.40, ts-node-dev@^1.0.0-pre.60, ts-node-dev@^1.0.0-pre.63: +ts-node-dev@^1.0.0-pre.40, ts-node-dev@^1.0.0-pre.63: version "1.1.1" resolved "https://registry.yarnpkg.com/ts-node-dev/-/ts-node-dev-1.1.1.tgz#b7602929395b1616b4aa99a3be0a4e121742283d" integrity sha512-kAO8LUZgXZSY0+PucMPsQ0Bbdv0x+lgbN7j8gcD4PuTI4uKC6YchekaspmYTBNilkiu+rQYkWJA7cK+Q8/B0tQ== @@ -10865,7 +10847,7 @@ ts-node@^7.0.1: source-map-support "^0.5.6" yn "^2.0.0" -ts-node@^8, ts-node@^8.10: +ts-node@^8: version "8.10.2" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.10.2.tgz#eee03764633b1234ddd37f8db9ec10b75ec7fb8d" integrity sha512-ISJJGgkIpDdBhWVu3jufsWpK3Rzo7bdiIXJjQc0ynKxVOVcg2oIrf2H2cejminGrptVc6q6/uynAHNCuWGbpVA== @@ -11041,7 +11023,7 @@ typeorm-typedi-extensions@^0.2.3: resolved "https://registry.yarnpkg.com/typeorm-typedi-extensions/-/typeorm-typedi-extensions-0.2.3.tgz#94fca2656206d771bf6d2242f5aab570511188e8" integrity sha512-T9i1NvRZNjPn9Jb8oT772ihfn6PwdqDVpzPCtKSqjkZGOgXrCkdyD3dDrzfMaoWJ1afU58bVx2CMb95FzT42Ow== -typeorm@^0.2.25, typeorm@^0.2.26, typeorm@^0.2.30: +typeorm@^0.2.25, typeorm@^0.2.26: version "0.2.30" resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.2.30.tgz#a0df2256402cbcdde8049a244437560495ce9b38" integrity sha512-qpr8AO3Phi6ZF7qMHOrRdNisVt8jE1KfmW0ooLFcXscA87aJ12aBPyB9cJfxGNjNwd7B3WIK9ZlBveWiqd74QA== @@ -11063,11 +11045,6 @@ typeorm@^0.2.25, typeorm@^0.2.26, typeorm@^0.2.30: yargonaut "^1.1.2" yargs "^16.0.3" -typescript@3.5.2: - version "3.5.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.2.tgz#a09e1dc69bc9551cadf17dba10ee42cf55e5d56c" - integrity sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA== - typescript@^3.8, typescript@^3.9.3, typescript@^3.9.7: version "3.9.7" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa" @@ -11169,13 +11146,6 @@ util.promisify@^1.0.0: has-symbols "^1.0.1" object.getownpropertydescriptors "^2.1.1" -util@^0.10.3: - version "0.10.4" - resolved "https://registry.yarnpkg.com/util/-/util-0.10.4.tgz#3aa0125bfe668a4672de58857d3ace27ecb76901" - integrity sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A== - dependencies: - inherits "2.0.3" - util@^0.12.3: version "0.12.3" resolved "https://registry.yarnpkg.com/util/-/util-0.12.3.tgz#971bb0292d2cc0c892dab7c6a5d37c2bec707888" From 3a07fa42a5c8a5c7d19b7c3ad7700ba0f3757640 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Tue, 16 Feb 2021 16:09:07 +0000 Subject: [PATCH 10/13] creating contributing guidelines --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index a522f0b4b..7a0c42bdb 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,12 @@ The monorepo contains the following sub-packages: * [Sample Project](https://github.com/dzhelezov/hydra/tree/d8c7f79fd26db49de753e0247ef561f5fcb7878f/packages/sample/README.md): A quickstart Hydra project set up against a publicly available Kusama indexer. Good starting point. * [Docs](docs/): In-depth documentation covering the Hydra pipeline and API features, such as full-text search, pagination, extensive filtering and a rich GraphQL dialect defining your schema! +## Contributing + +Thank you for you interest in contributing to Hydra and the Joy Stream ecosystem. Please don't hesitate to reach out to us on our [telegram channel](https://t.me/HydraDevs) if you have any questions about contributing. + +Each package has it's own README file which you should read before contributing. + +The first step is to fork this repository and then clone your fork. All changes should be done on a seperate branch and then submitted for review on a pull request. + + From f36e2f8591e7946ffb85fe90431ee4d1e01e9d35 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Tue, 16 Feb 2021 16:24:49 +0000 Subject: [PATCH 11/13] adding developer guidlines to hydra-cli --- packages/hydra-cli/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/hydra-cli/README.md b/packages/hydra-cli/README.md index 6606ba39c..140456887 100644 --- a/packages/hydra-cli/README.md +++ b/packages/hydra-cli/README.md @@ -175,3 +175,12 @@ To run it locally, inspect the settings in `.env` and run $ yarn configure:dev $ yarn server:start:dev ``` + +## Contributing +Thank you for you interest in contributing to Hydra CLI and the Joy Stream ecosystem. Please don't hesitate to reach out to us on our [telegram channel](https://t.me/HydraDevs) if you have any questions about contributing. + +All changes should be submited on a pull request. Before submitting a pull request you should run the linting and test commands: +``` +yarn lint +yarn test +``` From cec03c227dbf365919de2b0b7ba29ce65a3de164 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Thu, 18 Feb 2021 09:49:45 +0100 Subject: [PATCH 12/13] [hydra-cli] Separate includable schema files (#217) * Separate schema files https://github.com/Joystream/hydra/issues/188 * Update .gitignore * Refactored SchemaParser to accept folders * test for separate includable schema files * fixing relative path in codegen * Update SchemaParser.ts Lint error, unused import fix * Changelog and version bump * Update package.json Updating sample project hydra-cli version * reverting relative path fix --- .gitignore | 3 +- .idea/.gitignore | 5 +++ packages/hydra-cli/CHANGELOG.md | 4 +++ packages/hydra-cli/package.json | 2 +- .../hydra-cli/src/codegen/WarthogWrapper.ts | 2 +- packages/hydra-cli/src/commands/codegen.ts | 2 +- packages/hydra-cli/src/commands/scaffold.ts | 2 +- packages/hydra-cli/src/parse/SchemaParser.ts | 25 ++++++++++++++- .../fixtures/schema-folder/proposal.graphql | 24 ++++++++++++++ .../test/fixtures/schema-folder/tip.graphql | 32 +++++++++++++++++++ .../fixtures/schema-folder/transfer.graphql | 8 +++++ .../test/helpers/SchemaParser.test.ts | 5 +++ packages/sample/package.json | 2 +- yarn.lock | 4 +-- 14 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 packages/hydra-cli/test/fixtures/schema-folder/proposal.graphql create mode 100644 packages/hydra-cli/test/fixtures/schema-folder/tip.graphql create mode 100644 packages/hydra-cli/test/fixtures/schema-folder/transfer.graphql diff --git a/.gitignore b/.gitignore index 48323c844..bb92e5370 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ **/.eslintcache **/.nyc_output **/.DS_Store -**/lib \ No newline at end of file +**/lib +**/.idea/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..b58b603fe --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/packages/hydra-cli/CHANGELOG.md b/packages/hydra-cli/CHANGELOG.md index c2cf37c6d..066d2d595 100644 --- a/packages/hydra-cli/CHANGELOG.md +++ b/packages/hydra-cli/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.1.7 + +- `codegen --schema` now supports passing folders instead of single schema file + ## 0.1.6 - Fixed preview feature diff --git a/packages/hydra-cli/package.json b/packages/hydra-cli/package.json index 03e355da2..90eb5a650 100644 --- a/packages/hydra-cli/package.json +++ b/packages/hydra-cli/package.json @@ -1,7 +1,7 @@ { "name": "@dzlzv/hydra-cli", "description": "CLI tool for building a Hydra query node", - "version": "0.1.6", + "version": "0.1.7", "author": "metmirr @metmirr dzlzv @dzhelezov", "license": "MIT", "bin": { diff --git a/packages/hydra-cli/src/codegen/WarthogWrapper.ts b/packages/hydra-cli/src/codegen/WarthogWrapper.ts index 8133d4356..43e1114e8 100644 --- a/packages/hydra-cli/src/codegen/WarthogWrapper.ts +++ b/packages/hydra-cli/src/codegen/WarthogWrapper.ts @@ -33,7 +33,7 @@ export default class WarthogWrapper { ) if (!fs.existsSync(this.schemaResolvedPath)) { throw new Error( - `Cannot open the schema file ${this.schemaResolvedPath}. Check if it exists.` + `Cannot open the schema file or folder: ${this.schemaResolvedPath}. Check if it exists.` ) } } diff --git a/packages/hydra-cli/src/commands/codegen.ts b/packages/hydra-cli/src/commands/codegen.ts index 6f0a21a90..d4b36beb6 100644 --- a/packages/hydra-cli/src/commands/codegen.ts +++ b/packages/hydra-cli/src/commands/codegen.ts @@ -18,7 +18,7 @@ export default class Codegen extends Command { static flags = { schema: flags.string({ char: 's', - description: 'Schema path', + description: 'Schema path, can be file or directory', default: '../../schema.graphql', }), // pass --no-indexer to skip indexer generation diff --git a/packages/hydra-cli/src/commands/scaffold.ts b/packages/hydra-cli/src/commands/scaffold.ts index 8469ba59b..819a7ffa6 100644 --- a/packages/hydra-cli/src/commands/scaffold.ts +++ b/packages/hydra-cli/src/commands/scaffold.ts @@ -216,7 +216,7 @@ export default class Scaffold extends Command { return ctx } const typesJSON = (await cli.prompt( - 'Please provide the localtion of the type definitions JSON, relative to ./generated/indexer', + 'Please provide the location of the type definitions JSON, relative to ./generated/indexer', { default: '../../typedefs.json' } )) as string return { ...ctx, typesJSON } diff --git a/packages/hydra-cli/src/parse/SchemaParser.ts b/packages/hydra-cli/src/parse/SchemaParser.ts index a46ab9325..9e6057775 100644 --- a/packages/hydra-cli/src/parse/SchemaParser.ts +++ b/packages/hydra-cli/src/parse/SchemaParser.ts @@ -19,6 +19,7 @@ import { cloneDeep } from 'lodash' import { SCHEMA_DEFINITIONS_PREAMBLE } from './constant' import { SchemaDirective } from './SchemaDirective' import { FTSDirective } from './FTSDirective' +import path from 'path' const debug = Debug('qnode-cli:schema-parser') @@ -67,7 +68,7 @@ export class GraphQLSchemaParser { if (!fs.existsSync(schemaPath)) { throw new Error('Schema not found') } - const contents = fs.readFileSync(schemaPath, 'utf8') + const contents = this.getUnifiedSchema(schemaPath) this.schema = GraphQLSchemaParser.buildSchema(contents) this.namedTypes = [ ...Object.values(this.schema.getTypeMap()).filter( @@ -79,6 +80,28 @@ export class GraphQLSchemaParser { ) } + private getUnifiedSchema(schemaPath: string): string { + let schemaString = '' + if (fs.lstatSync(schemaPath).isDirectory()) { + fs.readdirSync(schemaPath).forEach((file) => { + if ( + fs.lstatSync(path.resolve(schemaPath, file)).isFile() && + path.extname(file) === '.graphql' + ) { + schemaString = schemaString.concat( + fs.readFileSync(path.resolve(schemaPath, file), 'utf8'), + '\n\n' + ) + } + }) + } else if (fs.lstatSync(schemaPath).isFile()) { + schemaString = fs.readFileSync(schemaPath, 'utf8') + } else { + throw new Error('Error reading schema file(s)') + } + return schemaString + } + private static buildPreamble(): string { let preamble = SCHEMA_DEFINITIONS_PREAMBLE DIRECTIVES.map((d) => (preamble += d.preamble + '\n')) diff --git a/packages/hydra-cli/test/fixtures/schema-folder/proposal.graphql b/packages/hydra-cli/test/fixtures/schema-folder/proposal.graphql new file mode 100644 index 000000000..09b1c5f89 --- /dev/null +++ b/packages/hydra-cli/test/fixtures/schema-folder/proposal.graphql @@ -0,0 +1,24 @@ +enum ProposalStatus { + NONE + REJECTED + APPROVED +} + +"A spending proposal" +type Proposal @entity { + "The account proposing it" + proposer: Bytes! + + "The (total) amount that should be paid if the proposal is accepted" + value: BigInt! + + "The account to whom the payment should be made if the proposal is accepted" + beneficiary: Bytes! + + "The amount held on deposit (reserved) for making this proposal" + bond: BigInt! + + proposalIndex: BigInt! @unique + + status: ProposalStatus +} \ No newline at end of file diff --git a/packages/hydra-cli/test/fixtures/schema-folder/tip.graphql b/packages/hydra-cli/test/fixtures/schema-folder/tip.graphql new file mode 100644 index 000000000..004962eee --- /dev/null +++ b/packages/hydra-cli/test/fixtures/schema-folder/tip.graphql @@ -0,0 +1,32 @@ +"The members who have voted for the tip." +type Tipper @entity { + tip: Tip! + tipper: Bytes! + tipValue: BigInt! +} + +type Tip @entity { + "The hash of the reason for the tip." + reason: Bytes! @unique + + "The account to be tipped." + who: Bytes! + + "The account who began this tip." + finder: Bytes! + + "The amount held on deposit for this tip." + deposit: BigInt + + "The block number at which this tip will close if Some." + closes: BigInt + + "The members who have voted for this tip." + tippers: [Tipper!] @derivedFrom(field: "tip") + + "Whether this tip should result in the finder taking a fee." + findersFee: Boolean! + + "Cancel the process of tipping" + retracted: Boolean! +} \ No newline at end of file diff --git a/packages/hydra-cli/test/fixtures/schema-folder/transfer.graphql b/packages/hydra-cli/test/fixtures/schema-folder/transfer.graphql new file mode 100644 index 000000000..bc143d917 --- /dev/null +++ b/packages/hydra-cli/test/fixtures/schema-folder/transfer.graphql @@ -0,0 +1,8 @@ +" All transfers " +type Transfer @entity { + from: Bytes! + to: Bytes! + value: BigInt! + comment: String @fulltext(query: "commentSearch") + block: Int! +} diff --git a/packages/hydra-cli/test/helpers/SchemaParser.test.ts b/packages/hydra-cli/test/helpers/SchemaParser.test.ts index f81664632..007fcc701 100644 --- a/packages/hydra-cli/test/helpers/SchemaParser.test.ts +++ b/packages/hydra-cli/test/helpers/SchemaParser.test.ts @@ -101,6 +101,11 @@ describe('SchemaParser', () => { ) }) + it('should load multiple files', () => { + const parser = new GraphQLSchemaParser('test/fixtures/schema-folder/') + expect(parser.getObjectDefinations()).length(4, 'Should detect 4 types') + }) + it('should visit directives', () => { const parser = new GraphQLSchemaParser('test/fixtures/single-type.graphql') const names: string[] = [] diff --git a/packages/sample/package.json b/packages/sample/package.json index 85a20912b..f2146d2ab 100644 --- a/packages/sample/package.json +++ b/packages/sample/package.json @@ -42,7 +42,7 @@ }, "devDependencies": { "envsub": "^4.0.7", - "@dzlzv/hydra-cli": "0.1.6", + "@dzlzv/hydra-cli": "0.1.7", "@dzlzv/hydra-common": "~0.0.3", "@dzlzv/hydra-db-utils": "^0.0.2", "@dzlzv/hydra-processor": "~0.1.1", diff --git a/yarn.lock b/yarn.lock index 3e9cc75ce..a3b00befb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10982,7 +10982,7 @@ ts-mockito@^2.6.1: dependencies: lodash "^4.17.5" -ts-node-dev@^1.0.0-pre.40, ts-node-dev@^1.0.0-pre.60, ts-node-dev@^1.0.0-pre.63: +ts-node-dev@^1.0.0-pre.40, ts-node-dev@^1.0.0-pre.63: version "1.1.1" resolved "https://registry.yarnpkg.com/ts-node-dev/-/ts-node-dev-1.1.1.tgz#b7602929395b1616b4aa99a3be0a4e121742283d" integrity sha512-kAO8LUZgXZSY0+PucMPsQ0Bbdv0x+lgbN7j8gcD4PuTI4uKC6YchekaspmYTBNilkiu+rQYkWJA7cK+Q8/B0tQ== @@ -11013,7 +11013,7 @@ ts-node@^7.0.1: source-map-support "^0.5.6" yn "^2.0.0" -ts-node@^8, ts-node@^8.10: +ts-node@^8: version "8.10.2" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.10.2.tgz#eee03764633b1234ddd37f8db9ec10b75ec7fb8d" integrity sha512-ISJJGgkIpDdBhWVu3jufsWpK3Rzo7bdiIXJjQc0ynKxVOVcg2oIrf2H2cejminGrptVc6q6/uynAHNCuWGbpVA== From e3e690aa3ea368be03d9121a42452f845a6c3550 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Thu, 18 Feb 2021 16:28:09 +0000 Subject: [PATCH 13/13] adding development scripts --- packages/hydra-cli/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/hydra-cli/README.md b/packages/hydra-cli/README.md index 140456887..9d4c81273 100644 --- a/packages/hydra-cli/README.md +++ b/packages/hydra-cli/README.md @@ -184,3 +184,9 @@ All changes should be submited on a pull request. Before submitting a pull reque yarn lint yarn test ``` + +Other development scripts include: +`yarn build` +`yarn postpack` +`yarn prepack` +`yarn version`