@ttoss/graphql-api 0.3.6 → 0.4.1
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 +4 -3
- package/dist/cli.js +39 -12
- package/dist/esm/cli.js +39 -12
- package/package.json +6 -4
- package/src/cli.ts +57 -18
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ This package provides an opinionated way to create an GraphQL API using ttoss ec
|
|
|
5
5
|
1. **Modular**: you can create your GraphQL API using modules, so you can reduce the complexity of a big GraphQL API.
|
|
6
6
|
1. **Relay**: ttoss uses Relay as the main GraphQL client, so this package implements the [Relay Server Specification](https://relay.dev/docs/guides/graphql-server-specification/).
|
|
7
7
|
1. **Build Schema**: as Relay needs an introspection query to work, this package provides a way to build the GraphQL schema by running `ttoss-graphl-api build-schema`.
|
|
8
|
+
1. **Build TypeScript Types**: this package provides a way to build the TypeScript types for your GraphQL schema by running `ttoss-graphl-api build-schema`.
|
|
8
9
|
1. **AppSync Support**: this package provides a way to create a GraphQL API that works with AWS AppSync, besides you can also create a local GraphQL API server.
|
|
9
10
|
|
|
10
11
|
## Installation
|
|
@@ -211,18 +212,18 @@ import { allow, deny, shield } from '@ttoss/graphql-api/shield';
|
|
|
211
212
|
|
|
212
213
|
## Building Schema
|
|
213
214
|
|
|
214
|
-
As Relay needs an introspection query to work, this package provides a way to build the GraphQL schema by running `ttoss-graphl-api build-schema`.
|
|
215
|
+
As Relay needs an introspection query to work, this package provides a way to build the GraphQL schema by running `ttoss-graphl-api build-schema`. It build the schema using the `schemaComposer` from `src/schemaComposer.ts` file and save the schema in `schema/schema.graphql` file and TypeScript types in `schema/types.ts` file.
|
|
215
216
|
|
|
216
217
|
```bash
|
|
217
218
|
ttoss-graphl-api build-schema
|
|
218
219
|
```
|
|
219
220
|
|
|
220
|
-
You can add the `
|
|
221
|
+
You can add the `build` script to your `package.json`:
|
|
221
222
|
|
|
222
223
|
```json
|
|
223
224
|
{
|
|
224
225
|
"scripts": {
|
|
225
|
-
"
|
|
226
|
+
"build": "ttoss-graphl-api build-schema"
|
|
226
227
|
}
|
|
227
228
|
}
|
|
228
229
|
```
|
package/dist/cli.js
CHANGED
|
@@ -29,6 +29,9 @@ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
|
29
29
|
// src/cli.ts
|
|
30
30
|
var fs = __toESM(require("fs"));
|
|
31
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_graphql = require("graphql");
|
|
32
35
|
var import_ts_node = require("ts-node");
|
|
33
36
|
var import_npmlog = __toESM(require("npmlog"));
|
|
34
37
|
var import_yargs = __toESM(require("yargs"));
|
|
@@ -37,15 +40,39 @@ var logPrefix = "graphql-api";
|
|
|
37
40
|
transpileOnly: true
|
|
38
41
|
});
|
|
39
42
|
var argv = (0, import_yargs.default)(process.argv.slice(2)).argv;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
(async () => {
|
|
44
|
+
if (argv._.includes("build-schema")) {
|
|
45
|
+
import_npmlog.default.info(logPrefix, "Building schema...");
|
|
46
|
+
const {
|
|
47
|
+
schemaComposer
|
|
48
|
+
} = require(path.resolve(process.cwd(), "src", "schemaComposer.ts"));
|
|
49
|
+
const sdl = schemaComposer.toSDL();
|
|
50
|
+
const codegenConfig = {
|
|
51
|
+
documents: [],
|
|
52
|
+
config: {
|
|
53
|
+
declarationKind: {
|
|
54
|
+
type: "interface",
|
|
55
|
+
interface: "interface"
|
|
56
|
+
},
|
|
57
|
+
namingConvention: "keep"
|
|
58
|
+
},
|
|
59
|
+
filename: "schema/types.ts",
|
|
60
|
+
schema: (0, import_graphql.parse)(sdl),
|
|
61
|
+
plugins: [{
|
|
62
|
+
typescript: {}
|
|
63
|
+
}],
|
|
64
|
+
pluginMap: {
|
|
65
|
+
typescript: typescriptPlugin
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
await fs.promises.mkdir("schema", {
|
|
69
|
+
recursive: true
|
|
70
|
+
});
|
|
71
|
+
await fs.promises.writeFile("schema/schema.graphql", sdl);
|
|
72
|
+
const typesOutput = await (0, import_core.codegen)(codegenConfig);
|
|
73
|
+
const typesOutputIgnore = ["/* eslint-disable */"].join("\n");
|
|
74
|
+
await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
|
|
75
|
+
${typesOutput}`);
|
|
76
|
+
import_npmlog.default.info(logPrefix, "Schema and types generated!");
|
|
77
|
+
}
|
|
78
|
+
})();
|
package/dist/esm/cli.js
CHANGED
|
@@ -4,6 +4,9 @@ import { __require } from "./chunk-O4CP4YC5.js";
|
|
|
4
4
|
// src/cli.ts
|
|
5
5
|
import * as fs from "fs";
|
|
6
6
|
import * as path from "path";
|
|
7
|
+
import * as typescriptPlugin from "@graphql-codegen/typescript";
|
|
8
|
+
import { codegen } from "@graphql-codegen/core";
|
|
9
|
+
import { parse } from "graphql";
|
|
7
10
|
import { register } from "ts-node";
|
|
8
11
|
import log from "npmlog";
|
|
9
12
|
import yargs from "yargs";
|
|
@@ -12,15 +15,39 @@ register({
|
|
|
12
15
|
transpileOnly: true
|
|
13
16
|
});
|
|
14
17
|
var argv = yargs(process.argv.slice(2)).argv;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
(async () => {
|
|
19
|
+
if (argv._.includes("build-schema")) {
|
|
20
|
+
log.info(logPrefix, "Building schema...");
|
|
21
|
+
const {
|
|
22
|
+
schemaComposer
|
|
23
|
+
} = __require(path.resolve(process.cwd(), "src", "schemaComposer.ts"));
|
|
24
|
+
const sdl = schemaComposer.toSDL();
|
|
25
|
+
const codegenConfig = {
|
|
26
|
+
documents: [],
|
|
27
|
+
config: {
|
|
28
|
+
declarationKind: {
|
|
29
|
+
type: "interface",
|
|
30
|
+
interface: "interface"
|
|
31
|
+
},
|
|
32
|
+
namingConvention: "keep"
|
|
33
|
+
},
|
|
34
|
+
filename: "schema/types.ts",
|
|
35
|
+
schema: parse(sdl),
|
|
36
|
+
plugins: [{
|
|
37
|
+
typescript: {}
|
|
38
|
+
}],
|
|
39
|
+
pluginMap: {
|
|
40
|
+
typescript: typescriptPlugin
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
await fs.promises.mkdir("schema", {
|
|
44
|
+
recursive: true
|
|
45
|
+
});
|
|
46
|
+
await fs.promises.writeFile("schema/schema.graphql", sdl);
|
|
47
|
+
const typesOutput = await codegen(codegenConfig);
|
|
48
|
+
const typesOutputIgnore = ["/* eslint-disable */"].join("\n");
|
|
49
|
+
await fs.promises.writeFile("schema/types.ts", `${typesOutputIgnore}
|
|
50
|
+
${typesOutput}`);
|
|
51
|
+
log.info(logPrefix, "Schema and types generated!");
|
|
52
|
+
}
|
|
53
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/graphql-api",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A library for building GraphQL APIs.",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "A library for building GraphQL APIs using ttoss ecosystem.",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
"sideEffects": false,
|
|
34
34
|
"typings": "dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@graphql-codegen/core": "^4.0.0",
|
|
37
|
+
"@graphql-codegen/typescript": "^4.0.1",
|
|
36
38
|
"graphql-compose": "^9.0.10",
|
|
37
39
|
"graphql-compose-connection": "^8.2.1",
|
|
38
|
-
"graphql-middleware": "^6.1.
|
|
40
|
+
"graphql-middleware": "^6.1.35",
|
|
39
41
|
"graphql-shield": "^7.6.5",
|
|
40
42
|
"npmlog": "^7.0.1",
|
|
41
43
|
"ts-node": "^10.9.1",
|
|
@@ -46,7 +48,7 @@
|
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
50
|
"@types/yargs": "^17.0.24",
|
|
49
|
-
"graphql": "^16.
|
|
51
|
+
"graphql": "^16.8.1",
|
|
50
52
|
"jest": "^29.6.2",
|
|
51
53
|
"tsup": "^7.1.0",
|
|
52
54
|
"@ttoss/config": "^1.30.6"
|
package/src/cli.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as typescriptPlugin from '@graphql-codegen/typescript';
|
|
4
|
+
import { codegen } from '@graphql-codegen/core';
|
|
5
|
+
import { parse } from 'graphql';
|
|
3
6
|
import { register } from 'ts-node';
|
|
4
7
|
import log from 'npmlog';
|
|
5
8
|
import yargs from 'yargs';
|
|
@@ -10,26 +13,62 @@ register({
|
|
|
10
13
|
transpileOnly: true,
|
|
11
14
|
});
|
|
12
15
|
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
17
|
const argv: any = yargs(process.argv.slice(2)).argv;
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
(async () => {
|
|
20
|
+
if (argv._.includes('build-schema')) {
|
|
21
|
+
log.info(logPrefix, 'Building schema...');
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
24
|
+
const { schemaComposer } = require(path.resolve(
|
|
25
|
+
process.cwd(),
|
|
26
|
+
'src',
|
|
27
|
+
'schemaComposer.ts'
|
|
28
|
+
));
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
const sdl = schemaComposer.toSDL();
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* https://the-guild.dev/graphql/codegen/docs/advanced/programmatic-usage
|
|
34
|
+
*/
|
|
35
|
+
const codegenConfig = {
|
|
36
|
+
documents: [],
|
|
37
|
+
config: {
|
|
38
|
+
declarationKind: {
|
|
39
|
+
type: 'interface',
|
|
40
|
+
interface: 'interface',
|
|
41
|
+
},
|
|
42
|
+
namingConvention: 'keep',
|
|
43
|
+
},
|
|
44
|
+
filename: 'schema/types.ts',
|
|
45
|
+
schema: parse(sdl),
|
|
46
|
+
plugins: [
|
|
47
|
+
{
|
|
48
|
+
typescript: {},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
pluginMap: {
|
|
52
|
+
typescript: typescriptPlugin,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
31
55
|
|
|
32
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Save to schema/schema.graphql. schema folder might not exist.
|
|
58
|
+
*/
|
|
59
|
+
await fs.promises.mkdir('schema', { recursive: true });
|
|
33
60
|
|
|
34
|
-
|
|
35
|
-
|
|
61
|
+
await fs.promises.writeFile('schema/schema.graphql', sdl);
|
|
62
|
+
|
|
63
|
+
const typesOutput = await codegen(codegenConfig);
|
|
64
|
+
|
|
65
|
+
const typesOutputIgnore = ['/* eslint-disable */'].join('\n');
|
|
66
|
+
|
|
67
|
+
await fs.promises.writeFile(
|
|
68
|
+
'schema/types.ts',
|
|
69
|
+
`${typesOutputIgnore}\n${typesOutput}`
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
log.info(logPrefix, 'Schema and types generated!');
|
|
73
|
+
}
|
|
74
|
+
})();
|