@ttoss/graphql-api 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,6 +34,19 @@ const UserTC = schemaComposer.createObjectTC({
34
34
  });
35
35
  ```
36
36
 
37
+ This library uses the `tsconfig.json` file from the target package it is being applied on. If you are using relative imports in your package you can skip this section, but, if you use path aliases in your typescript code by leveraging the [`paths`](https://www.typescriptlang.org/tsconfig#paths) property, the [`baseUrl`](https://www.typescriptlang.org/tsconfig#baseUrl) must be filled accordingly.This is needed because in order to interpret the path aliases, `ts-node` uses [`tsconfig-paths`](https://github.com/dividab/tsconfig-paths) to resolve the modules that uses this config, and `tsconfig-paths` needs both `baseUrl` and `paths` values to be non-null. A `tsconfig.json` example that follows such recommendations is given below:
38
+
39
+ ```json
40
+ {
41
+ "compilerOptions": {
42
+ "baseUrl": ".",
43
+ "paths": {
44
+ "src/*": ["src/*"]
45
+ }
46
+ }
47
+ }
48
+ ```
49
+
37
50
  ### Resolvers
38
51
 
39
52
  ### Integrate All Modules
package/dist/cli.js CHANGED
@@ -34,9 +34,28 @@ var import_core = require("@graphql-codegen/core");
34
34
  var import_helpers = require("yargs/helpers");
35
35
  var import_graphql = require("graphql");
36
36
  var import_ts_node = require("ts-node");
37
+ var import_tsconfig_paths = require("tsconfig-paths");
37
38
  var import_npmlog = __toESM(require("npmlog"));
38
39
  var import_yargs = __toESM(require("yargs"));
39
40
  var logPrefix = "graphql-api";
41
+ var tsConfig = require(path.resolve(process.cwd(), "tsconfig.json"));
42
+ var cleanup = () => {};
43
+ try {
44
+ const baseUrl = tsConfig?.compilerOptions?.baseUrl;
45
+ const paths = tsConfig?.compilerOptions?.paths;
46
+ if (baseUrl && !paths || !baseUrl && paths) {
47
+ throw new Error("tsconfig.json must have 'baseUrl' and 'paths' properties.");
48
+ }
49
+ if (baseUrl && paths) {
50
+ cleanup = (0, import_tsconfig_paths.register)({
51
+ baseUrl: tsConfig.compilerOptions.baseUrl,
52
+ paths: tsConfig.compilerOptions.paths
53
+ });
54
+ }
55
+ } catch (error) {
56
+ error instanceof Error && import_npmlog.default.error(logPrefix, error.message);
57
+ process.exit(1);
58
+ }
40
59
  (0, import_ts_node.register)({
41
60
  transpileOnly: true,
42
61
  compilerOptions: {
@@ -84,6 +103,7 @@ var buildSchema = async ({
84
103
  const typesOutputIgnore = ["/* eslint-disable */"].join("\n");
85
104
  await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
86
105
  ${typesOutput}`);
106
+ cleanup();
87
107
  import_npmlog.default.info(logPrefix, "Schema and types generated!");
88
108
  };
89
109
  (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).command("build-schema", "fetch the contents of the URL", yargs2 => {
package/dist/esm/cli.js CHANGED
@@ -9,9 +9,28 @@ import { codegen } from "@graphql-codegen/core";
9
9
  import { hideBin } from "yargs/helpers";
10
10
  import { parse } from "graphql";
11
11
  import { register } from "ts-node";
12
+ import { register as registerTsPaths } from "tsconfig-paths";
12
13
  import log from "npmlog";
13
14
  import yargs from "yargs";
14
15
  var logPrefix = "graphql-api";
16
+ var tsConfig = __require(path.resolve(process.cwd(), "tsconfig.json"));
17
+ var cleanup = () => {};
18
+ try {
19
+ const baseUrl = tsConfig?.compilerOptions?.baseUrl;
20
+ const paths = tsConfig?.compilerOptions?.paths;
21
+ if (baseUrl && !paths || !baseUrl && paths) {
22
+ throw new Error("tsconfig.json must have 'baseUrl' and 'paths' properties.");
23
+ }
24
+ if (baseUrl && paths) {
25
+ cleanup = registerTsPaths({
26
+ baseUrl: tsConfig.compilerOptions.baseUrl,
27
+ paths: tsConfig.compilerOptions.paths
28
+ });
29
+ }
30
+ } catch (error) {
31
+ error instanceof Error && log.error(logPrefix, error.message);
32
+ process.exit(1);
33
+ }
15
34
  register({
16
35
  transpileOnly: true,
17
36
  compilerOptions: {
@@ -59,6 +78,7 @@ var buildSchema = async ({
59
78
  const typesOutputIgnore = ["/* eslint-disable */"].join("\n");
60
79
  await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
61
80
  ${typesOutput}`);
81
+ cleanup();
62
82
  log.info(logPrefix, "Schema and types generated!");
63
83
  };
64
84
  yargs(hideBin(process.argv)).command("build-schema", "fetch the contents of the URL", yargs2 => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/graphql-api",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "A library for building GraphQL APIs using ttoss ecosystem.",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -40,8 +40,9 @@
40
40
  "graphql-shield": "^7.6.5",
41
41
  "npmlog": "^7.0.1",
42
42
  "ts-node": "^10.9.2",
43
+ "tsconfig-paths": "^4.2.0",
43
44
  "yargs": "^17.7.2",
44
- "@ttoss/ids": "^0.1.1"
45
+ "@ttoss/ids": "^0.2.0"
45
46
  },
46
47
  "peerDependencies": {
47
48
  "graphql": "^16.6.0"
@@ -51,7 +52,7 @@
51
52
  "graphql": "^16.8.1",
52
53
  "jest": "^29.7.0",
53
54
  "tsup": "^8.0.2",
54
- "@ttoss/config": "^1.31.5"
55
+ "@ttoss/config": "^1.32.0"
55
56
  },
56
57
  "keywords": [
57
58
  "api",
package/src/cli.ts CHANGED
@@ -5,10 +5,32 @@ import { codegen } from '@graphql-codegen/core';
5
5
  import { hideBin } from 'yargs/helpers';
6
6
  import { parse } from 'graphql';
7
7
  import { register } from 'ts-node';
8
+ import { register as registerTsPaths } from 'tsconfig-paths';
8
9
  import log from 'npmlog';
9
10
  import yargs from 'yargs';
10
11
 
11
12
  const logPrefix = 'graphql-api';
13
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
14
+ const tsConfig = require(path.resolve(process.cwd(), 'tsconfig.json'));
15
+ let cleanup = () => {};
16
+ try {
17
+ const baseUrl = tsConfig?.compilerOptions?.baseUrl;
18
+ const paths = tsConfig?.compilerOptions?.paths;
19
+ if ((baseUrl && !paths) || (!baseUrl && paths)) {
20
+ throw new Error(
21
+ "tsconfig.json must have 'baseUrl' and 'paths' properties."
22
+ );
23
+ }
24
+ if (baseUrl && paths) {
25
+ cleanup = registerTsPaths({
26
+ baseUrl: tsConfig.compilerOptions.baseUrl,
27
+ paths: tsConfig.compilerOptions.paths,
28
+ });
29
+ }
30
+ } catch (error: unknown) {
31
+ error instanceof Error && log.error(logPrefix, error.message);
32
+ process.exit(1);
33
+ }
12
34
 
13
35
  register({
14
36
  transpileOnly: true,
@@ -77,7 +99,7 @@ const buildSchema = async ({ directory }: { directory: string }) => {
77
99
  'schema/types.ts',
78
100
  `${typesOutputIgnore}\n${typesOutput}`
79
101
  );
80
-
102
+ cleanup();
81
103
  log.info(logPrefix, 'Schema and types generated!');
82
104
  };
83
105