@ttoss/graphql-api 0.7.7 → 0.8.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 +39 -6
- package/bin/cli.js +1 -1
- package/dist/esm/cli.js +121 -43
- package/dist/esm/index.js +2 -3
- package/dist/index.d.ts +1 -1
- package/package.json +11 -12
- package/dist/cli.d.mts +0 -2
- package/dist/cli.js +0 -120
- package/dist/esm/chunk-NT3ZWSM6.js +0 -8
- package/dist/index.d.mts +0 -16
- package/dist/index.js +0 -211
- package/dist/shield.d.mts +0 -2
- package/dist/shield.js +0 -29
package/README.md
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
# @ttoss/graphql-api
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package offers an opinionated approach to building a GraphQL API using the **ttoss ecosystem modules**. It is designed to provide a resilient and scalable solution for creating complex GraphQL APIs while focusing on the following goals:
|
|
4
4
|
|
|
5
|
-
1. **Modular**:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
1. **
|
|
9
|
-
|
|
5
|
+
1. **Modular Design**:
|
|
6
|
+
Build your GraphQL API using modules to simplify and organize the development of large, complex APIs.
|
|
7
|
+
|
|
8
|
+
1. **Relay Compatibility**:
|
|
9
|
+
As **Relay** is the primary GraphQL client in the ttoss ecosystem, this package implements the [Relay Server Specification](https://relay.dev/docs/guides/graphql-server-specification/) for seamless client-server interaction.
|
|
10
|
+
|
|
11
|
+
1. **Schema Building**:
|
|
12
|
+
Generate the GraphQL schema required for Relay's introspection queries by running:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
ttoss-graphql-api build-schema
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
1. **TypeScript Types Generation**:
|
|
19
|
+
Automatically generate TypeScript types for your GraphQL schema with the same command:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
ttoss-graphql-api build-schema
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
1. **AWS AppSync Support**:
|
|
26
|
+
Create GraphQL APIs compatible with AWS AppSync. Additionally, this package includes support for running a local GraphQL API server for development and testing purposes.
|
|
27
|
+
|
|
28
|
+
## ESM Only
|
|
29
|
+
|
|
30
|
+
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
|
10
31
|
|
|
11
32
|
## Installation
|
|
12
33
|
|
|
@@ -445,12 +466,24 @@ You can add the `build-schema` script to your `package.json`:
|
|
|
445
466
|
}
|
|
446
467
|
```
|
|
447
468
|
|
|
469
|
+
### Options
|
|
470
|
+
|
|
471
|
+
#### `--directory`/`-d`
|
|
472
|
+
|
|
448
473
|
If your `schemaComposer` is in a different directory, you can pass the `--directory`/`-d` option to `ttoss-graphl-api build-schema` command:
|
|
449
474
|
|
|
450
475
|
```bash
|
|
451
476
|
ttoss-graphl-api build-schema -d tests
|
|
452
477
|
```
|
|
453
478
|
|
|
479
|
+
#### `--external`
|
|
480
|
+
|
|
481
|
+
External dependencies to ignore during build. If you don't set this option, the `build-schema` command will use the `dependencies` and `devDependencies` from your `package.json` file.
|
|
482
|
+
|
|
483
|
+
```bash
|
|
484
|
+
ttoss-graphl-api build-schema --external graphql-compose,graphql
|
|
485
|
+
```
|
|
486
|
+
|
|
454
487
|
## How to Create Tests
|
|
455
488
|
|
|
456
489
|
We recommend testing the whole GraphQL API using the `graphql` object and the schema composer to provide the schema. For example:
|
package/bin/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import '../dist/esm/cli.js';
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,45 +1,126 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
import { __require } from "./chunk-NT3ZWSM6.js";
|
|
3
2
|
|
|
4
3
|
// src/cli.ts
|
|
4
|
+
import * as esbuild from "esbuild";
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
6
|
import * as path from "node:path";
|
|
7
7
|
import * as typescriptPlugin from "@graphql-codegen/typescript";
|
|
8
|
+
import { Command } from "commander";
|
|
8
9
|
import { codegen } from "@graphql-codegen/core";
|
|
9
|
-
import { hideBin } from "yargs/helpers";
|
|
10
10
|
import { parse } from "graphql";
|
|
11
|
-
import { register } from "ts-node";
|
|
12
|
-
import { register as registerTsPaths } from "tsconfig-paths";
|
|
13
11
|
import log from "npmlog";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
|
|
13
|
+
// package.json
|
|
14
|
+
var package_default = {
|
|
15
|
+
name: "@ttoss/graphql-api",
|
|
16
|
+
version: "0.8.0",
|
|
17
|
+
description: "A library for building GraphQL APIs using ttoss ecosystem.",
|
|
18
|
+
license: "MIT",
|
|
19
|
+
author: "ttoss",
|
|
20
|
+
contributors: ["Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"],
|
|
21
|
+
repository: {
|
|
22
|
+
type: "git",
|
|
23
|
+
url: "https://github.com/ttoss/ttoss.git",
|
|
24
|
+
directory: "packages/graphql-api"
|
|
25
|
+
},
|
|
26
|
+
type: "module",
|
|
27
|
+
exports: {
|
|
28
|
+
".": "./src/index.ts",
|
|
29
|
+
"./shield": "./src/shield.ts"
|
|
30
|
+
},
|
|
31
|
+
bin: {
|
|
32
|
+
"ttoss-graphql-api": "./bin/cli.js"
|
|
33
|
+
},
|
|
34
|
+
files: ["dist"],
|
|
35
|
+
scripts: {
|
|
36
|
+
"build-config": "tsup-node",
|
|
37
|
+
test: "jest --projects tests/unit"
|
|
38
|
+
},
|
|
39
|
+
sideEffects: false,
|
|
40
|
+
dependencies: {
|
|
41
|
+
"@graphql-codegen/core": "^4.0.2",
|
|
42
|
+
"@graphql-codegen/typescript": "^4.1.2",
|
|
43
|
+
"@ttoss/ids": "workspace:^",
|
|
44
|
+
esbuild: "^0.24.0",
|
|
45
|
+
"graphql-compose": "^9.0.11",
|
|
46
|
+
"graphql-compose-connection": "^8.2.1",
|
|
47
|
+
"graphql-middleware": "^6.1.35",
|
|
48
|
+
"graphql-shield": "^7.6.5",
|
|
49
|
+
npmlog: "^7.0.1"
|
|
50
|
+
},
|
|
51
|
+
peerDependencies: {
|
|
52
|
+
graphql: "^16.6.0"
|
|
53
|
+
},
|
|
54
|
+
devDependencies: {
|
|
55
|
+
"@ttoss/config": "workspace:^",
|
|
56
|
+
commander: "^12.1.0",
|
|
57
|
+
graphql: "^16.9.0",
|
|
58
|
+
jest: "^29.7.0",
|
|
59
|
+
tsup: "^8.3.5"
|
|
60
|
+
},
|
|
61
|
+
keywords: ["api", "graphql"],
|
|
62
|
+
publishConfig: {
|
|
63
|
+
access: "public",
|
|
64
|
+
exports: {
|
|
65
|
+
".": {
|
|
66
|
+
import: "./dist/esm/index.js",
|
|
67
|
+
require: "./dist/index.js",
|
|
68
|
+
types: "./dist/index.d.ts"
|
|
69
|
+
},
|
|
70
|
+
"./shield": {
|
|
71
|
+
import: "./dist/esm/shield.js",
|
|
72
|
+
require: "./dist/shield.js",
|
|
73
|
+
types: "./dist/shield.d.ts"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
provenance: true
|
|
23
77
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/cli.ts
|
|
81
|
+
var logPrefix = "graphql-api";
|
|
82
|
+
var importSchemaComposer = async ({
|
|
83
|
+
external,
|
|
84
|
+
schemaComposerPath
|
|
85
|
+
}) => {
|
|
86
|
+
const lastEntryPointName = schemaComposerPath.split("/").pop();
|
|
87
|
+
const filename = lastEntryPointName?.split(".")[0];
|
|
88
|
+
const outfile = path.resolve(process.cwd(), "out", filename + ".js");
|
|
89
|
+
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
90
|
+
const packageJson = await fs.promises.readFile(packageJsonPath, "utf-8");
|
|
91
|
+
const dependencies = Object.keys(JSON.parse(packageJson).dependencies).filter(dependency => {
|
|
92
|
+
if (dependency.startsWith("@ttoss/")) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (dependency === "graphql") {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
100
|
+
const result = await esbuild.build({
|
|
101
|
+
bundle: true,
|
|
102
|
+
entryPoints: [schemaComposerPath],
|
|
103
|
+
external: external || dependencies,
|
|
104
|
+
format: "esm",
|
|
105
|
+
outfile,
|
|
106
|
+
platform: "node",
|
|
107
|
+
target: "ES2023",
|
|
108
|
+
treeShaking: true
|
|
109
|
+
});
|
|
110
|
+
if (result.errors.length > 0) {
|
|
111
|
+
console.error("Error building config file: ", filename);
|
|
112
|
+
throw result.errors;
|
|
29
113
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
transpileOnly: true,
|
|
36
|
-
compilerOptions: {
|
|
37
|
-
module: "NodeNext",
|
|
38
|
-
moduleResolution: "NodeNext"
|
|
114
|
+
try {
|
|
115
|
+
return await import(outfile);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error("Failed importing build config file: ", filename);
|
|
118
|
+
throw error;
|
|
39
119
|
}
|
|
40
|
-
}
|
|
120
|
+
};
|
|
41
121
|
var buildSchema = async ({
|
|
42
|
-
directory
|
|
122
|
+
directory,
|
|
123
|
+
external
|
|
43
124
|
}) => {
|
|
44
125
|
log.info(logPrefix, "Building schema...");
|
|
45
126
|
await fs.promises.mkdir("schema", {
|
|
@@ -50,9 +131,13 @@ var buildSchema = async ({
|
|
|
50
131
|
} catch {
|
|
51
132
|
await fs.promises.writeFile("schema/types.ts", "");
|
|
52
133
|
}
|
|
134
|
+
const schemaComposerPath = path.resolve(process.cwd(), directory, "schemaComposer.ts");
|
|
53
135
|
const {
|
|
54
136
|
schemaComposer
|
|
55
|
-
} =
|
|
137
|
+
} = await importSchemaComposer({
|
|
138
|
+
external,
|
|
139
|
+
schemaComposerPath
|
|
140
|
+
});
|
|
56
141
|
const sdl = schemaComposer.toSDL();
|
|
57
142
|
const codegenConfig = {
|
|
58
143
|
documents: [],
|
|
@@ -78,18 +163,11 @@ var buildSchema = async ({
|
|
|
78
163
|
const typesOutputIgnore = ["/* eslint-disable */"].join("\n");
|
|
79
164
|
await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
|
|
80
165
|
${typesOutput}`);
|
|
81
|
-
cleanup();
|
|
82
166
|
log.info(logPrefix, "Schema and types generated!");
|
|
83
167
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
default: "src"
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}, argv => {
|
|
94
|
-
return buildSchema(argv);
|
|
95
|
-
}).demandCommand(1).strictOptions().parse();
|
|
168
|
+
var program = new Command();
|
|
169
|
+
program.name("ttoss-graphql-api").version(package_default.version, "-v, --version", "Output the current version of the GraphQL API");
|
|
170
|
+
program.command("build-schema").option("-d, --directory <directory>", "Schema composer directory", "src").option("--external <external...>", "External dependencies to ignore during build").action(options => {
|
|
171
|
+
return buildSchema(options);
|
|
172
|
+
});
|
|
173
|
+
program.parse(process.argv);
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
import "./chunk-NT3ZWSM6.js";
|
|
3
2
|
|
|
4
3
|
// src/composeWithRelay/composeWithRelay.ts
|
|
5
4
|
import { ObjectTypeComposer } from "graphql-compose";
|
|
@@ -135,7 +134,7 @@ import { schemaComposer } from "graphql-compose";
|
|
|
135
134
|
composeWithRelay(schemaComposer.Query);
|
|
136
135
|
|
|
137
136
|
// src/index.ts
|
|
138
|
-
import {
|
|
137
|
+
import { composeWithConnection } from "graphql-compose-connection";
|
|
139
138
|
export * from "graphql-compose";
|
|
140
139
|
|
|
141
140
|
// src/buildSchema.ts
|
|
@@ -158,4 +157,4 @@ var buildSchema = ({
|
|
|
158
157
|
}
|
|
159
158
|
return schema;
|
|
160
159
|
};
|
|
161
|
-
export { buildSchema,
|
|
160
|
+
export { buildSchema, composeWithConnection, composeWithRelay };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ObjectTypeComposer, SchemaComposer } from 'graphql-compose';
|
|
2
2
|
export * from 'graphql-compose';
|
|
3
|
-
export {
|
|
3
|
+
export { composeWithConnection } from 'graphql-compose-connection';
|
|
4
4
|
import { GraphQLSchema } from 'graphql';
|
|
5
5
|
import { IMiddleware, IMiddlewareGenerator } from 'graphql-middleware';
|
|
6
6
|
export { IMiddleware as Middleware } from 'graphql-middleware';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/graphql-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A library for building GraphQL APIs using ttoss ecosystem.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"url": "https://github.com/ttoss/ttoss.git",
|
|
13
13
|
"directory": "packages/graphql-api"
|
|
14
14
|
},
|
|
15
|
+
"type": "module",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
17
18
|
"import": "./dist/esm/index.js",
|
|
@@ -33,26 +34,24 @@
|
|
|
33
34
|
"sideEffects": false,
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@graphql-codegen/core": "^4.0.2",
|
|
36
|
-
"@graphql-codegen/typescript": "^4.
|
|
37
|
-
"
|
|
37
|
+
"@graphql-codegen/typescript": "^4.1.2",
|
|
38
|
+
"esbuild": "^0.24.0",
|
|
39
|
+
"graphql-compose": "^9.0.11",
|
|
38
40
|
"graphql-compose-connection": "^8.2.1",
|
|
39
41
|
"graphql-middleware": "^6.1.35",
|
|
40
42
|
"graphql-shield": "^7.6.5",
|
|
41
43
|
"npmlog": "^7.0.1",
|
|
42
|
-
"
|
|
43
|
-
"tsconfig-paths": "^4.2.0",
|
|
44
|
-
"yargs": "^17.7.2",
|
|
45
|
-
"@ttoss/ids": "^0.2.13"
|
|
44
|
+
"@ttoss/ids": "^0.3.0"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
47
|
"graphql": "^16.6.0"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"
|
|
52
|
-
"graphql": "^16.
|
|
50
|
+
"commander": "^12.1.0",
|
|
51
|
+
"graphql": "^16.9.0",
|
|
53
52
|
"jest": "^29.7.0",
|
|
54
|
-
"tsup": "^8.3.
|
|
55
|
-
"@ttoss/config": "^1.
|
|
53
|
+
"tsup": "^8.3.5",
|
|
54
|
+
"@ttoss/config": "^1.35.0"
|
|
56
55
|
},
|
|
57
56
|
"keywords": [
|
|
58
57
|
"api",
|
|
@@ -64,6 +63,6 @@
|
|
|
64
63
|
},
|
|
65
64
|
"scripts": {
|
|
66
65
|
"build-config": "tsup-node",
|
|
67
|
-
"test": "jest"
|
|
66
|
+
"test": "jest --projects tests/unit"
|
|
68
67
|
}
|
|
69
68
|
}
|
package/dist/cli.d.mts
DELETED
package/dist/cli.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var __create = Object.create;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: () => from[key],
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
-
value: mod,
|
|
26
|
-
enumerable: true
|
|
27
|
-
}) : target, mod));
|
|
28
|
-
|
|
29
|
-
// src/cli.ts
|
|
30
|
-
var fs = __toESM(require("fs"));
|
|
31
|
-
var path = __toESM(require("path"));
|
|
32
|
-
var typescriptPlugin = __toESM(require("@graphql-codegen/typescript"));
|
|
33
|
-
var import_core = require("@graphql-codegen/core");
|
|
34
|
-
var import_helpers = require("yargs/helpers");
|
|
35
|
-
var import_graphql = require("graphql");
|
|
36
|
-
var import_ts_node = require("ts-node");
|
|
37
|
-
var import_tsconfig_paths = require("tsconfig-paths");
|
|
38
|
-
var import_npmlog = __toESM(require("npmlog"));
|
|
39
|
-
var import_yargs = __toESM(require("yargs"));
|
|
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
|
-
}
|
|
59
|
-
(0, import_ts_node.register)({
|
|
60
|
-
transpileOnly: true,
|
|
61
|
-
compilerOptions: {
|
|
62
|
-
module: "NodeNext",
|
|
63
|
-
moduleResolution: "NodeNext"
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
var buildSchema = async ({
|
|
67
|
-
directory
|
|
68
|
-
}) => {
|
|
69
|
-
import_npmlog.default.info(logPrefix, "Building schema...");
|
|
70
|
-
await fs.promises.mkdir("schema", {
|
|
71
|
-
recursive: true
|
|
72
|
-
});
|
|
73
|
-
try {
|
|
74
|
-
await fs.promises.access("schema/types.ts");
|
|
75
|
-
} catch {
|
|
76
|
-
await fs.promises.writeFile("schema/types.ts", "");
|
|
77
|
-
}
|
|
78
|
-
const {
|
|
79
|
-
schemaComposer
|
|
80
|
-
} = require(path.resolve(process.cwd(), directory, "schemaComposer.ts"));
|
|
81
|
-
const sdl = schemaComposer.toSDL();
|
|
82
|
-
const codegenConfig = {
|
|
83
|
-
documents: [],
|
|
84
|
-
config: {
|
|
85
|
-
declarationKind: {
|
|
86
|
-
type: "interface",
|
|
87
|
-
interface: "interface"
|
|
88
|
-
},
|
|
89
|
-
namingConvention: "keep"
|
|
90
|
-
},
|
|
91
|
-
filename: "schema/types.ts",
|
|
92
|
-
schema: (0, import_graphql.parse)(sdl),
|
|
93
|
-
plugins: [{
|
|
94
|
-
typescript: {}
|
|
95
|
-
}],
|
|
96
|
-
pluginMap: {
|
|
97
|
-
typescript: typescriptPlugin
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
await fs.promises.writeFile("schema/schema.graphql", sdl);
|
|
101
|
-
import_npmlog.default.info(logPrefix, "Generating types...");
|
|
102
|
-
const typesOutput = await (0, import_core.codegen)(codegenConfig);
|
|
103
|
-
const typesOutputIgnore = ["/* eslint-disable */"].join("\n");
|
|
104
|
-
await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
|
|
105
|
-
${typesOutput}`);
|
|
106
|
-
cleanup();
|
|
107
|
-
import_npmlog.default.info(logPrefix, "Schema and types generated!");
|
|
108
|
-
};
|
|
109
|
-
(0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).command("build-schema", "fetch the contents of the URL", yargs2 => {
|
|
110
|
-
return yargs2.options({
|
|
111
|
-
directory: {
|
|
112
|
-
alias: ["d"],
|
|
113
|
-
type: "string",
|
|
114
|
-
describe: "Schema composer directory relative to the project root",
|
|
115
|
-
default: "src"
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}, argv => {
|
|
119
|
-
return buildSchema(argv);
|
|
120
|
-
}).demandCommand(1).strictOptions().parse();
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
var __require = /* @__PURE__ */(x => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function (x) {
|
|
5
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
export { __require };
|
package/dist/index.d.mts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ObjectTypeComposer, SchemaComposer } from 'graphql-compose';
|
|
2
|
-
export * from 'graphql-compose';
|
|
3
|
-
export { default as composeWithConnection } from 'graphql-compose-connection';
|
|
4
|
-
import { GraphQLSchema } from 'graphql';
|
|
5
|
-
import { IMiddleware, IMiddlewareGenerator } from 'graphql-middleware';
|
|
6
|
-
export { IMiddleware as Middleware } from 'graphql-middleware';
|
|
7
|
-
|
|
8
|
-
declare const composeWithRelay: <TContext>(tc: ObjectTypeComposer<any, TContext>) => ObjectTypeComposer<any, TContext>;
|
|
9
|
-
|
|
10
|
-
type BuildSchemaInput<TContext = unknown> = {
|
|
11
|
-
schemaComposer: SchemaComposer<TContext>;
|
|
12
|
-
middlewares?: (IMiddleware | IMiddlewareGenerator<unknown, TContext, unknown>)[];
|
|
13
|
-
};
|
|
14
|
-
declare const buildSchema: ({ schemaComposer, middlewares, }: BuildSchemaInput) => GraphQLSchema;
|
|
15
|
-
|
|
16
|
-
export { type BuildSchemaInput, buildSchema, composeWithRelay };
|
package/dist/index.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var __create = Object.create;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __export = (target, all) => {
|
|
11
|
-
for (var name in all) __defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
-
get: () => from[key],
|
|
20
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return to;
|
|
24
|
-
};
|
|
25
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
26
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
32
|
-
value: mod,
|
|
33
|
-
enumerable: true
|
|
34
|
-
}) : target, mod));
|
|
35
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
36
|
-
value: true
|
|
37
|
-
}), mod);
|
|
38
|
-
|
|
39
|
-
// src/index.ts
|
|
40
|
-
var src_exports = {};
|
|
41
|
-
__export(src_exports, {
|
|
42
|
-
buildSchema: () => buildSchema,
|
|
43
|
-
composeWithConnection: () => import_graphql_compose_connection.default,
|
|
44
|
-
composeWithRelay: () => composeWithRelay
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(src_exports);
|
|
47
|
-
|
|
48
|
-
// src/composeWithRelay/composeWithRelay.ts
|
|
49
|
-
var import_graphql_compose3 = require("graphql-compose");
|
|
50
|
-
|
|
51
|
-
// src/composeWithRelay/nodeFieldConfig.ts
|
|
52
|
-
var import_graphql_compose = require("graphql-compose");
|
|
53
|
-
var import_ids = require("@ttoss/ids");
|
|
54
|
-
var getNodeFieldConfig = (typeMapForRelayNode, nodeInterface) => {
|
|
55
|
-
return {
|
|
56
|
-
description: "Fetches an object that has globally unique ID among all types",
|
|
57
|
-
type: nodeInterface,
|
|
58
|
-
args: {
|
|
59
|
-
id: {
|
|
60
|
-
type: "ID!",
|
|
61
|
-
description: "The globally unique ID among all types"
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
// eslint-disable-next-line max-params
|
|
65
|
-
resolve: (source, args, context, info) => {
|
|
66
|
-
if (!args.id || !(typeof args.id === "string")) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
const {
|
|
70
|
-
type
|
|
71
|
-
} = (0, import_ids.fromGlobalId)(args.id);
|
|
72
|
-
if (!typeMapForRelayNode[type]) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
const {
|
|
76
|
-
tc,
|
|
77
|
-
resolver: findById
|
|
78
|
-
} = typeMapForRelayNode[type];
|
|
79
|
-
if (findById && findById.resolve && tc) {
|
|
80
|
-
const graphqlType = tc.getType();
|
|
81
|
-
let projection;
|
|
82
|
-
if (info) {
|
|
83
|
-
projection = (0, import_graphql_compose.getProjectionFromAST)({
|
|
84
|
-
...info,
|
|
85
|
-
returnType: graphqlType
|
|
86
|
-
});
|
|
87
|
-
} else {
|
|
88
|
-
projection = {};
|
|
89
|
-
}
|
|
90
|
-
const idArgName = Object.keys(findById.args)[0];
|
|
91
|
-
return findById.resolve({
|
|
92
|
-
source,
|
|
93
|
-
args: {
|
|
94
|
-
[idArgName]: args.id
|
|
95
|
-
},
|
|
96
|
-
// eg. mongoose has _id fieldname, so should map
|
|
97
|
-
context,
|
|
98
|
-
info,
|
|
99
|
-
projection
|
|
100
|
-
}).then(res => {
|
|
101
|
-
if (!res) {
|
|
102
|
-
return res;
|
|
103
|
-
}
|
|
104
|
-
res.__nodeType = graphqlType;
|
|
105
|
-
return res;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// src/composeWithRelay/nodeInterface.ts
|
|
114
|
-
var import_graphql_compose2 = require("graphql-compose");
|
|
115
|
-
var NodeTC = import_graphql_compose2.InterfaceTypeComposer.createTemp({
|
|
116
|
-
name: "Node",
|
|
117
|
-
description: "An object, that can be fetched by the globally unique ID among all types.",
|
|
118
|
-
fields: {
|
|
119
|
-
id: {
|
|
120
|
-
type: "ID!",
|
|
121
|
-
description: "The globally unique ID among all types."
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
resolveType: payload => {
|
|
125
|
-
return payload.__nodeType.name ? payload.__nodeType.name : null;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
var NodeInterface = NodeTC.getType();
|
|
129
|
-
var getNodeInterface = sc => {
|
|
130
|
-
if (sc.hasInstance("Node", import_graphql_compose2.InterfaceTypeComposer)) {
|
|
131
|
-
return sc.get("Node");
|
|
132
|
-
}
|
|
133
|
-
sc.set("Node", NodeTC);
|
|
134
|
-
return NodeTC;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// src/composeWithRelay/composeWithRelay.ts
|
|
138
|
-
var import_ids2 = require("@ttoss/ids");
|
|
139
|
-
var TypeMapForRelayNode = {};
|
|
140
|
-
var composeWithRelay = tc => {
|
|
141
|
-
if (!(tc instanceof import_graphql_compose3.ObjectTypeComposer)) {
|
|
142
|
-
throw new Error("You should provide ObjectTypeComposer instance to composeWithRelay method");
|
|
143
|
-
}
|
|
144
|
-
const nodeInterface = getNodeInterface(tc.schemaComposer);
|
|
145
|
-
const nodeFieldConfig = getNodeFieldConfig(TypeMapForRelayNode, nodeInterface);
|
|
146
|
-
if (tc.getTypeName() === "Query" || tc.getTypeName() === "RootQuery") {
|
|
147
|
-
tc.setField("node", nodeFieldConfig);
|
|
148
|
-
return tc;
|
|
149
|
-
}
|
|
150
|
-
if (tc.getTypeName() === "Mutation" || tc.getTypeName() === "RootMutation") {
|
|
151
|
-
return tc;
|
|
152
|
-
}
|
|
153
|
-
if (!tc.hasRecordIdFn()) {
|
|
154
|
-
throw new Error(`ObjectTypeComposer(${tc.getTypeName()}) should have recordIdFn. This function returns ID from provided object.`);
|
|
155
|
-
}
|
|
156
|
-
const findById = tc.getResolver("findById");
|
|
157
|
-
if (!findById) {
|
|
158
|
-
throw new Error(`ObjectTypeComposer(${tc.getTypeName()}) provided to composeWithRelay should have findById resolver.`);
|
|
159
|
-
}
|
|
160
|
-
TypeMapForRelayNode[tc.getTypeName()] = {
|
|
161
|
-
resolver: findById,
|
|
162
|
-
tc
|
|
163
|
-
};
|
|
164
|
-
tc.addFields({
|
|
165
|
-
id: {
|
|
166
|
-
type: "ID!",
|
|
167
|
-
description: "The globally unique ID among all types",
|
|
168
|
-
resolve: source => {
|
|
169
|
-
return (0, import_ids2.toGlobalId)(tc.getTypeName(), tc.getRecordId(source).toString());
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
tc.addInterface(nodeInterface);
|
|
174
|
-
return tc;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// src/composeWithRelay/index.ts
|
|
178
|
-
var import_graphql_compose4 = require("graphql-compose");
|
|
179
|
-
composeWithRelay(import_graphql_compose4.schemaComposer.Query);
|
|
180
|
-
|
|
181
|
-
// src/index.ts
|
|
182
|
-
var import_graphql_compose_connection = __toESM(require("graphql-compose-connection"));
|
|
183
|
-
__reExport(src_exports, require("graphql-compose"), module.exports);
|
|
184
|
-
|
|
185
|
-
// src/buildSchema.ts
|
|
186
|
-
var import_graphql_middleware = require("graphql-middleware");
|
|
187
|
-
var buildSchema = ({
|
|
188
|
-
schemaComposer: schemaComposer2,
|
|
189
|
-
middlewares
|
|
190
|
-
}) => {
|
|
191
|
-
if (!schemaComposer2) {
|
|
192
|
-
throw new Error("No schemaComposer provided");
|
|
193
|
-
}
|
|
194
|
-
const schema = schemaComposer2.buildSchema();
|
|
195
|
-
if (middlewares) {
|
|
196
|
-
return (0, import_graphql_middleware.applyMiddleware)(schema, ...middlewares.map(middleware => {
|
|
197
|
-
if (middleware.generate) {
|
|
198
|
-
return middleware.generate(schema);
|
|
199
|
-
}
|
|
200
|
-
return middleware;
|
|
201
|
-
}));
|
|
202
|
-
}
|
|
203
|
-
return schema;
|
|
204
|
-
};
|
|
205
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
206
|
-
0 && (module.exports = {
|
|
207
|
-
buildSchema,
|
|
208
|
-
composeWithConnection,
|
|
209
|
-
composeWithRelay,
|
|
210
|
-
...require("graphql-compose")
|
|
211
|
-
});
|
package/dist/shield.d.mts
DELETED
package/dist/shield.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
-
get: () => from[key],
|
|
12
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value: true
|
|
20
|
-
}), mod);
|
|
21
|
-
|
|
22
|
-
// src/shield.ts
|
|
23
|
-
var shield_exports = {};
|
|
24
|
-
module.exports = __toCommonJS(shield_exports);
|
|
25
|
-
__reExport(shield_exports, require("graphql-shield"), module.exports);
|
|
26
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
-
0 && (module.exports = {
|
|
28
|
-
...require("graphql-shield")
|
|
29
|
-
});
|