Skip to content

Commit

Permalink
feat(client-ts): combine graphql schemas in client package
Browse files Browse the repository at this point in the history
dev tooling often prefers a single combined schema, which is now
included as an option.

Closes #273
  • Loading branch information
rhyslbw committed Sep 21, 2020
1 parent 004a971 commit bd52a16
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 2 deletions.
Binary file not shown.
Binary file not shown.
Binary file added packages-cache/@graphql-tools-merge-6.2.3.tgz
Binary file not shown.
Binary file added packages-cache/@graphql-tools-schema-6.2.3.tgz
Binary file not shown.
Binary file added packages-cache/@graphql-tools-utils-6.2.3.tgz
Binary file not shown.
Binary file added packages-cache/tslib-2.0.1.tgz
Binary file not shown.
7 changes: 6 additions & 1 deletion packages/client-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"scripts": {
"build": "graphql-codegen -c codegen.cardano-db-hasura.yml && graphql-codegen -c codegen.genesis.yml && tsc",
"cleanup": "./scripts/cleanup.sh",
"combine-schema": "node ./util/combineGraphQLSchema.js",
"lint": "eslint --ignore-path ../../.eslintignore \"**/*.ts\"",
"prepack": "yarn build && ./scripts/embed_schema.sh",
"prepack": "yarn build && ./scripts/embed_schema.sh && node ./util/combineGraphQLSchema.js",
"postpack": "yarn cleanup",
"test": "shx echo No tests in this package"
},
Expand All @@ -38,6 +39,10 @@
"lib": "src"
},
"devDependencies": {
"@graphql-tools/load-files": "^6.2.3",
"@graphql-tools/merge": "^6.2.3",
"@graphql-tools/schema": "^6.2.3",
"@graphql-tools/utils": "^6.2.3",
"shx": "^0.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/client-ts/scripts/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ CLIENT_TS_ROOT="$(dirname "$(dirname "$(readlink -fm "$0")")")"
shx rm -rf \
$CLIENT_TS_ROOT/api/**/*/*index.d.ts \
$CLIENT_TS_ROOT/api/**/*/*graphql_types* \
$CLIENT_TS_ROOT/api/**/*/*.graphql
$CLIENT_TS_ROOT/api/*.graphql
17 changes: 17 additions & 0 deletions packages/client-ts/util/combineGraphQLSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require('fs');
const path = require('path');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const { printSchemaWithDirectives } = require('@graphql-tools/utils');
const { makeExecutableSchema } = require('@graphql-tools/schema');

const cardanoDbHasuraSchema = loadFilesSync(path.resolve(__dirname, '..', 'api', 'cardano-db-hasura', 'schema.graphql'));
const genesisSchema = loadFilesSync(path.resolve(__dirname, '..', 'api', 'genesis', 'schema.graphql'));
const mergedTypes = mergeTypeDefs([cardanoDbHasuraSchema, genesisSchema], {
throwOnConflict: true
});

const executableSchema = makeExecutableSchema({ typeDefs: [mergedTypes] });
const schema = printSchemaWithDirectives(executableSchema);

fs.writeFileSync(path.resolve(__dirname, '..','api', 'schema.graphql'), schema);
48 changes: 48 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
resolved "https://registry.yarnpkg.com/@ardatan/aggregate-error/-/aggregate-error-0.0.1.tgz#1403ac5de10d8ca689fc1f65844c27179ae1d44f"
integrity sha512-UQ9BequOTIavs0pTHLMwQwKQF8tTV1oezY/H2O9chA+JNPFZSua55xpU5dPSjAU9/jLJ1VwU+HJuTVN8u7S6Fg==

"@ardatan/[email protected]":
version "0.0.6"
resolved "https://registry.yarnpkg.com/@ardatan/aggregate-error/-/aggregate-error-0.0.6.tgz#fe6924771ea40fc98dc7a7045c2e872dc8527609"
integrity sha512-vyrkEHG1jrukmzTPtyWB4NLPauUw5bQeg4uhn8f+1SSynmrOcyvlb1GKQjjgoBzElLdfXCRYX8UnBlhklOHYRQ==
dependencies:
tslib "~2.0.1"

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
Expand Down Expand Up @@ -766,6 +773,16 @@
fs-extra "9.0.1"
tslib "~2.0.0"

"@graphql-tools/load-files@^6.2.3":
version "6.2.3"
resolved "https://registry.yarnpkg.com/@graphql-tools/load-files/-/load-files-6.2.3.tgz#f2b851911622e9f305fbb268a84876bf03062e01"
integrity sha512-VXl/dixmNCuxxa/1trjh2ogx967lwfZetWY3gN3ck2qWjd4ERmYFnsXd2xcXRRTK4SOZilEaFFXU2tmtYy23xg==
dependencies:
fs-extra "9.0.1"
globby "11.0.1"
tslib "~2.0.1"
unixify "1.0.0"

"@graphql-tools/load@^6.0.0":
version "6.0.12"
resolved "https://registry.yarnpkg.com/@graphql-tools/load/-/load-6.0.12.tgz#3f40a5aae35d880e55fc52f797c861d868a47fdc"
Expand All @@ -790,6 +807,15 @@
"@graphql-tools/utils" "6.0.12"
tslib "~2.0.0"

"@graphql-tools/merge@^6.2.3":
version "6.2.3"
resolved "https://registry.yarnpkg.com/@graphql-tools/merge/-/merge-6.2.3.tgz#df6d84d9182bd289985da4cc3a45515a7c2135df"
integrity sha512-qSSxdM2AKjnAHuChcnxIfzsGej78B56EE6ZD3tXMtKJOMQMhk4T4yXnKRHEw8fw7ZtNk/KqCmb6LJHy8Ws8frg==
dependencies:
"@graphql-tools/schema" "6.2.3"
"@graphql-tools/utils" "6.2.3"
tslib "~2.0.1"

"@graphql-tools/prisma-loader@^6.0.0":
version "6.0.12"
resolved "https://registry.yarnpkg.com/@graphql-tools/prisma-loader/-/prisma-loader-6.0.12.tgz#30b639236138a1db2c33a9a39a53abcc0be64e91"
Expand Down Expand Up @@ -817,6 +843,14 @@
"@graphql-tools/utils" "6.0.12"
tslib "~2.0.0"

"@graphql-tools/[email protected]", "@graphql-tools/schema@^6.2.3":
version "6.2.3"
resolved "https://registry.yarnpkg.com/@graphql-tools/schema/-/schema-6.2.3.tgz#7ffc8e5f49d9a81f446fb8db87a6f5d07b1fba8e"
integrity sha512-CV5vDfQhXidssLK5hjT55FfwRAvBoGW53lVBl0rbXrbsSX7H9iVHdUf4UaDIlMc6WcnnzOrRiue/khHz3rzDEg==
dependencies:
"@graphql-tools/utils" "6.2.3"
tslib "~2.0.1"

"@graphql-tools/[email protected]", "@graphql-tools/url-loader@^6.0.0":
version "6.0.12"
resolved "https://registry.yarnpkg.com/@graphql-tools/url-loader/-/url-loader-6.0.12.tgz#ea6e2e542ed0944efa8d3276c57e1979df095ecb"
Expand All @@ -840,6 +874,15 @@
"@ardatan/aggregate-error" "0.0.1"
camel-case "4.1.1"

"@graphql-tools/[email protected]", "@graphql-tools/utils@^6.2.3":
version "6.2.3"
resolved "https://registry.yarnpkg.com/@graphql-tools/utils/-/utils-6.2.3.tgz#235636b47a62f12f3dddbdd30b2986fc03f3a5fa"
integrity sha512-eOhZy4y23r6AddokBqvFpQybtHvhTyZCc3VFWn8eIqF92vre90UKHbCX6Cf6VBo6i7l0ZwChPPbUzEiHOk+HJQ==
dependencies:
"@ardatan/aggregate-error" "0.0.6"
camel-case "4.1.1"
tslib "~2.0.1"

"@graphql-tools/[email protected]", "@graphql-tools/wrap@^6.0.9":
version "6.0.12"
resolved "https://registry.yarnpkg.com/@graphql-tools/wrap/-/wrap-6.0.12.tgz#fb0b9b74de30ca69877c9f806f681c98eabe49f4"
Expand Down Expand Up @@ -8102,6 +8145,11 @@ tslib@^2.0.0, tslib@~2.0.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.0.tgz#18d13fc2dce04051e20f074cc8387fd8089ce4f3"
integrity sha512-lTqkx847PI7xEDYJntxZH89L2/aXInsyF2luSafe/+0fHOMjlBNXdH6th7f70qxLDhul7KZK0zC8V5ZIyHl0/g==

tslib@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.1.tgz#410eb0d113e5b6356490eec749603725b021b43e"
integrity sha512-SgIkNheinmEBgx1IUNirK0TUD4X9yjjBRTqqjggWCU3pUEqIk3/Uwl3yRixYKT6WjQuGiwDv4NomL3wqRCj+CQ==

tsutils@^3.17.1:
version "3.17.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759"
Expand Down

0 comments on commit bd52a16

Please sign in to comment.