@newmo/graphql-fake-server 0.9.8 → 0.10.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 +48 -0
- package/dist/esm/cli.d.ts +2 -5
- package/dist/esm/cli.d.ts.map +1 -1
- package/dist/esm/cli.js +28 -89
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/config.d.ts +75 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +81 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server.d.ts +2 -22
- package/dist/esm/server.d.ts.map +1 -1
- package/dist/esm/server.js +6 -11
- package/dist/esm/server.js.map +1 -1
- package/package.json +3 -3
- package/src/cli.ts +34 -90
- package/src/config.ts +156 -0
- package/src/index.ts +5 -0
- package/src/server.ts +16 -33
package/README.md
CHANGED
|
@@ -12,6 +12,54 @@ See <https://github.com/newmo-oss/graphql-fake-server>
|
|
|
12
12
|
- Support `/fake` API
|
|
13
13
|
- Support `/graphql` API
|
|
14
14
|
|
|
15
|
+
## Config
|
|
16
|
+
|
|
17
|
+
Please See [src/config.ts](src/config.ts)
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
/**
|
|
21
|
+
* Configuration for the fake server.
|
|
22
|
+
*/
|
|
23
|
+
export type FakeServerConfig = {
|
|
24
|
+
/**
|
|
25
|
+
* The path to the GraphQL schema file.
|
|
26
|
+
*/
|
|
27
|
+
schemaFilePath: string;
|
|
28
|
+
ports?: {
|
|
29
|
+
/**
|
|
30
|
+
* Fake Server port.
|
|
31
|
+
* Default is 4000.
|
|
32
|
+
*/
|
|
33
|
+
fakeServer?: number | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Apollo Server port.
|
|
36
|
+
* It provides the GraphQL Playground.
|
|
37
|
+
* Default is 4002.
|
|
38
|
+
*/
|
|
39
|
+
apolloServer?: number | undefined;
|
|
40
|
+
} | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The maximum number of registered sequences.
|
|
43
|
+
* Default is 1000.
|
|
44
|
+
*/
|
|
45
|
+
maxRegisteredSequences?: number | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The maximum number of depth of field recursion.
|
|
48
|
+
* Default is 3.
|
|
49
|
+
*/
|
|
50
|
+
maxFieldRecursionDepth?: RawConfig["maxFieldRecursionDepth"] | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The maximum number of depth of complexity of query
|
|
53
|
+
* Default is 4
|
|
54
|
+
*/
|
|
55
|
+
maxQueryDepth?: number | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Default values for scalar types.
|
|
58
|
+
*/
|
|
59
|
+
defaultValues?: RawConfig["defaultValues"] | undefined;
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
15
63
|
## Tests
|
|
16
64
|
|
|
17
65
|
```sh
|
package/dist/esm/cli.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
export declare const cli: {
|
|
3
3
|
values: {
|
|
4
|
+
cwd: string | undefined;
|
|
4
5
|
schema: string | undefined;
|
|
5
|
-
|
|
6
|
-
apolloPort: string | undefined;
|
|
7
|
-
maxRegisteredSequences: string | undefined;
|
|
8
|
-
maxQueryDepth: string | undefined;
|
|
9
|
-
maxFieldRecursionDepth: string | undefined;
|
|
6
|
+
config: string | undefined;
|
|
10
7
|
logLevel: string | undefined;
|
|
11
8
|
};
|
|
12
9
|
positionals: [];
|
package/dist/esm/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AA8BA,eAAO,MAAM,GAAG;;;;;;;;CAsBd,CAAC;AACH,eAAO,MAAM,GAAG,iBAEb,UAAU,KAAS,QAAQ;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB,CAuCA,CAAC"}
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
+
import { loadConfig, loadFakeServerConfigFromCLI, } from "./config.js";
|
|
3
4
|
import { createFakeServer } from "./index.js";
|
|
4
5
|
import { createLogger } from "./logger.js";
|
|
5
6
|
const HELP = `
|
|
@@ -7,44 +8,35 @@ Usage: npx @newmo/graphql-fake-server --schema <path> [options]
|
|
|
7
8
|
|
|
8
9
|
Options:
|
|
9
10
|
|
|
10
|
-
--
|
|
11
|
-
--
|
|
11
|
+
--config <path> Path to a config file
|
|
12
|
+
--schema <path> Path to a schema file
|
|
12
13
|
--logLevel <logLevel> log level: debug, info, warn, error
|
|
14
|
+
--cwd <path> Current working directory
|
|
15
|
+
|
|
16
|
+
Examples:
|
|
17
|
+
|
|
18
|
+
# Provide a schema file - use default config
|
|
19
|
+
npx @newmo/graphql-fake-server --schema api.graphql
|
|
20
|
+
# Use a config file
|
|
21
|
+
npx @newmo/graphql-fake-server --config graphql-fake-server.config.js
|
|
13
22
|
|
|
14
23
|
`;
|
|
15
24
|
// cli foo.graphql
|
|
16
25
|
export const cli = parseArgs({
|
|
17
26
|
args: process.argv.slice(2),
|
|
18
27
|
options: {
|
|
19
|
-
|
|
20
|
-
schema: {
|
|
21
|
-
type: "string",
|
|
22
|
-
description: "Path to the schema file. e.g. schema.graphql",
|
|
23
|
-
},
|
|
24
|
-
mainPort: {
|
|
28
|
+
cwd: {
|
|
25
29
|
type: "string",
|
|
26
|
-
description: "
|
|
27
|
-
default:
|
|
30
|
+
description: "Current working directory",
|
|
31
|
+
default: process.cwd(),
|
|
28
32
|
},
|
|
29
|
-
|
|
30
|
-
type: "string",
|
|
31
|
-
description: "Port to run the server on",
|
|
32
|
-
default: "4002",
|
|
33
|
-
},
|
|
34
|
-
maxRegisteredSequences: {
|
|
35
|
-
type: "string",
|
|
36
|
-
description: "Max number of registered sequences.",
|
|
37
|
-
default: "1000",
|
|
38
|
-
},
|
|
39
|
-
maxQueryDepth: {
|
|
33
|
+
schema: {
|
|
40
34
|
type: "string",
|
|
41
|
-
description: "
|
|
42
|
-
default: "3",
|
|
35
|
+
description: "Path to a schema file",
|
|
43
36
|
},
|
|
44
|
-
|
|
37
|
+
config: {
|
|
45
38
|
type: "string",
|
|
46
|
-
description: "
|
|
47
|
-
default: "4",
|
|
39
|
+
description: "Path to a config file",
|
|
48
40
|
},
|
|
49
41
|
logLevel: {
|
|
50
42
|
type: "string",
|
|
@@ -62,71 +54,18 @@ export const run = async ({ values, } = cli) => {
|
|
|
62
54
|
exitCode: 1,
|
|
63
55
|
};
|
|
64
56
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
stderr: "--schema is required",
|
|
72
|
-
exitCode: 1,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
const mainPort = values.mainPort ? Number.parseInt(values.mainPort, 10) : Number.NaN;
|
|
76
|
-
const apolloPort = values.apolloPort ? Number.parseInt(values.apolloPort, 10) : Number.NaN;
|
|
77
|
-
if (Number.isNaN(mainPort) || Number.isNaN(apolloPort)) {
|
|
78
|
-
logger.info(HELP);
|
|
79
|
-
return {
|
|
80
|
-
stdout: "",
|
|
81
|
-
stderr: "port must be a number",
|
|
82
|
-
exitCode: 1,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
const maxFieldRecursionDepth = values.maxFieldRecursionDepth
|
|
86
|
-
? Number.parseInt(values.maxFieldRecursionDepth, 10)
|
|
87
|
-
: Number.NaN;
|
|
88
|
-
if (Number.isNaN(maxFieldRecursionDepth)) {
|
|
89
|
-
logger.info(HELP);
|
|
90
|
-
return {
|
|
91
|
-
stdout: "",
|
|
92
|
-
stderr: "maxFieldRecursionDepth must be a number",
|
|
93
|
-
exitCode: 1,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const maxQueryDepth = values.maxQueryDepth
|
|
97
|
-
? Number.parseInt(values.maxQueryDepth, 10)
|
|
98
|
-
: Number.NaN;
|
|
99
|
-
if (Number.isNaN(maxQueryDepth)) {
|
|
100
|
-
logger.info(HELP);
|
|
101
|
-
return {
|
|
102
|
-
stdout: "",
|
|
103
|
-
stderr: "maxQueryDepth must be a number",
|
|
104
|
-
exitCode: 1,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
const maxRegisteredSequences = values.maxRegisteredSequences
|
|
108
|
-
? Number.parseInt(values.maxRegisteredSequences, 10)
|
|
109
|
-
: Number.NaN;
|
|
110
|
-
if (Number.isNaN(maxRegisteredSequences)) {
|
|
111
|
-
logger.info(HELP);
|
|
112
|
-
return {
|
|
113
|
-
stdout: "",
|
|
114
|
-
stderr: "maxRegisteredSequences must be a number",
|
|
115
|
-
exitCode: 1,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
const server = await createFakeServer({
|
|
120
|
-
schemaFilePath: schemaPath,
|
|
121
|
-
maxRegisteredSequences,
|
|
122
|
-
maxFieldRecursionDepth,
|
|
123
|
-
maxQueryDepth,
|
|
57
|
+
const schemaFilePath = values.schema;
|
|
58
|
+
// prefer config file over CLI options
|
|
59
|
+
const config = values.config
|
|
60
|
+
? await loadConfig(values.cwd ?? process.cwd(), values.config)
|
|
61
|
+
: loadFakeServerConfigFromCLI({
|
|
62
|
+
schemaFilePath,
|
|
124
63
|
logLevel,
|
|
125
|
-
ports: {
|
|
126
|
-
fakeServer: mainPort,
|
|
127
|
-
apolloServer: apolloPort,
|
|
128
|
-
},
|
|
129
64
|
});
|
|
65
|
+
const logger = createLogger(config.logLevel ?? logLevel);
|
|
66
|
+
logger.debug("[fake-server-cli] config", config);
|
|
67
|
+
try {
|
|
68
|
+
const server = await createFakeServer(config);
|
|
130
69
|
const { urls } = await server.start();
|
|
131
70
|
logger.info(`🚀 GraphQL Fake Server listening at: ${urls.fakeServer}`);
|
|
132
71
|
return {
|
package/dist/esm/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAiB,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,IAAI,GAAG
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACH,UAAU,EACV,2BAA2B,GAG9B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAiB,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;CAiBZ,CAAC;AACF,kBAAkB;AAClB,MAAM,CAAC,MAAM,GAAG,GAAG,SAAS,CAAC;IACzB,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3B,OAAO,EAAE;QACL,GAAG,EAAE;YACD,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,2BAA2B;YACxC,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;SACzB;QACD,MAAM,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,uBAAuB;SACvC;QACD,MAA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AAO;YACH,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,IAAI;SAClB,CAAC;IACN,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpB,OAAO;YACH,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,IAAI,KAAK,CAAC,wBAAwB,EAAE;gBACxC,KAAK,EAAE,KAAK;aACf,CAAC;YACF,QAAQ,EAAE,CAAC;SACd,CAAC;IACN,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { RawConfig } from "@newmo/graphql-fake-core";
|
|
2
|
+
import type { LogLevel } from "./logger.js";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the fake server.
|
|
5
|
+
*/
|
|
6
|
+
export type FakeServerConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* The path to the GraphQL schema file.
|
|
9
|
+
*/
|
|
10
|
+
schemaFilePath: string;
|
|
11
|
+
ports?: {
|
|
12
|
+
/**
|
|
13
|
+
* Fake Server port.
|
|
14
|
+
* Default is 4000.
|
|
15
|
+
*/
|
|
16
|
+
fakeServer?: number | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Apollo Server port.
|
|
19
|
+
* It provides the GraphQL Playground.
|
|
20
|
+
* Default is 4002.
|
|
21
|
+
*/
|
|
22
|
+
apolloServer?: number | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The maximum number of registered sequences.
|
|
26
|
+
* Default is 1000.
|
|
27
|
+
*/
|
|
28
|
+
maxRegisteredSequences?: number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The maximum number of depth of field recursion.
|
|
31
|
+
* Default is 3.
|
|
32
|
+
*/
|
|
33
|
+
maxFieldRecursionDepth?: RawConfig["maxFieldRecursionDepth"] | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The maximum number of depth of complexity of query
|
|
36
|
+
* Default is 4
|
|
37
|
+
*/
|
|
38
|
+
maxQueryDepth?: number | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Default values for scalar types.
|
|
41
|
+
*/
|
|
42
|
+
defaultValues?: RawConfig["defaultValues"] | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Log level.
|
|
45
|
+
*/
|
|
46
|
+
logLevel?: LogLevel | undefined;
|
|
47
|
+
};
|
|
48
|
+
export type RequiredFakeServerConfig = {
|
|
49
|
+
schemaFilePath: string;
|
|
50
|
+
ports: {
|
|
51
|
+
fakeServer: number;
|
|
52
|
+
apolloServer: number;
|
|
53
|
+
};
|
|
54
|
+
maxRegisteredSequences: number;
|
|
55
|
+
maxFieldRecursionDepth: number;
|
|
56
|
+
maxQueryDepth: number;
|
|
57
|
+
defaultValues: RawConfig["defaultValues"];
|
|
58
|
+
logLevel: LogLevel;
|
|
59
|
+
};
|
|
60
|
+
export declare const normalizeFakeServerConfig: (config: FakeServerConfig) => RequiredFakeServerConfig;
|
|
61
|
+
export declare const validateFakeServerConfig: (config: FakeServerConfig) => FakeServerConfig;
|
|
62
|
+
/**
|
|
63
|
+
* Load the fake server configuration from the file.
|
|
64
|
+
* @param configPath
|
|
65
|
+
*/
|
|
66
|
+
export declare const loadConfig: (cwd: string, configPath: string) => Promise<RequiredFakeServerConfig>;
|
|
67
|
+
/**
|
|
68
|
+
* Load the fake server configuration from the CLI flags.
|
|
69
|
+
* @param cliFlag
|
|
70
|
+
*/
|
|
71
|
+
export declare const loadFakeServerConfigFromCLI: ({ schemaFilePath, logLevel, }: {
|
|
72
|
+
schemaFilePath?: string | undefined;
|
|
73
|
+
logLevel?: LogLevel | undefined;
|
|
74
|
+
}) => RequiredFakeServerConfig;
|
|
75
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"A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QACd,MAAM,cACC,MAAM,KACnB,QAAQ,wBAAwB,CAMlC,CAAC;AACF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,kCAGrC;IACC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CACnC,KAAG,wBAYH,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
export const normalizeFakeServerConfig = (config) => {
|
|
4
|
+
return {
|
|
5
|
+
schemaFilePath: config.schemaFilePath,
|
|
6
|
+
ports: {
|
|
7
|
+
fakeServer: config.ports?.fakeServer ?? 4000,
|
|
8
|
+
apolloServer: config.ports?.apolloServer ?? 4002,
|
|
9
|
+
},
|
|
10
|
+
maxRegisteredSequences: config.maxRegisteredSequences ?? 1000,
|
|
11
|
+
maxFieldRecursionDepth: config.maxFieldRecursionDepth ?? 3,
|
|
12
|
+
maxQueryDepth: config.maxQueryDepth ?? 4,
|
|
13
|
+
defaultValues: config.defaultValues ?? {},
|
|
14
|
+
logLevel: config.logLevel ?? "info",
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export const validateFakeServerConfig = (config) => {
|
|
18
|
+
if (!config.schemaFilePath) {
|
|
19
|
+
throw new Error("The schemaFilePath is required.");
|
|
20
|
+
}
|
|
21
|
+
if (typeof config.schemaFilePath !== "string") {
|
|
22
|
+
throw new Error("The schemaPath must be a string.");
|
|
23
|
+
}
|
|
24
|
+
if (config.ports) {
|
|
25
|
+
if (typeof config.ports !== "object") {
|
|
26
|
+
throw new Error("The ports must be an object.");
|
|
27
|
+
}
|
|
28
|
+
if (config.ports.fakeServer && typeof config.ports.fakeServer !== "number") {
|
|
29
|
+
throw new Error("The fakeServer port must be a number.");
|
|
30
|
+
}
|
|
31
|
+
if (config.ports.apolloServer && typeof config.ports.apolloServer !== "number") {
|
|
32
|
+
throw new Error("The apolloServer port must be a number.");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (config.maxRegisteredSequences && typeof config.maxRegisteredSequences !== "number") {
|
|
36
|
+
throw new Error("The maxRegisteredSequences must be a number.");
|
|
37
|
+
}
|
|
38
|
+
if (config.maxFieldRecursionDepth && typeof config.maxFieldRecursionDepth !== "number") {
|
|
39
|
+
throw new Error("The maxFieldRecursionDepth must be a number.");
|
|
40
|
+
}
|
|
41
|
+
if (config.maxQueryDepth && typeof config.maxQueryDepth !== "number") {
|
|
42
|
+
throw new Error("The maxQueryDepth must be a number.");
|
|
43
|
+
}
|
|
44
|
+
if (config.defaultValues) {
|
|
45
|
+
if (typeof config.defaultValues !== "object") {
|
|
46
|
+
throw new Error("The defaultValues must be an object.");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// ["debug", "info", "warn", "error"].includes(logLevel)
|
|
50
|
+
if (config.logLevel && !["debug", "info", "warn", "error"].includes(config.logLevel)) {
|
|
51
|
+
throw new Error("The logLevel must be one of 'debug', 'info', 'warn', 'error'.");
|
|
52
|
+
}
|
|
53
|
+
return config;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Load the fake server configuration from the file.
|
|
57
|
+
* @param configPath
|
|
58
|
+
*/
|
|
59
|
+
export const loadConfig = async (cwd, configPath) => {
|
|
60
|
+
const fileUrl = pathToFileURL(path.resolve(cwd, configPath)).href;
|
|
61
|
+
const { default: config } = await import(fileUrl);
|
|
62
|
+
const normalizedConfig = normalizeFakeServerConfig(config);
|
|
63
|
+
validateFakeServerConfig(normalizedConfig);
|
|
64
|
+
return normalizedConfig;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Load the fake server configuration from the CLI flags.
|
|
68
|
+
* @param cliFlag
|
|
69
|
+
*/
|
|
70
|
+
export const loadFakeServerConfigFromCLI = ({ schemaFilePath, logLevel, }) => {
|
|
71
|
+
if (!schemaFilePath) {
|
|
72
|
+
throw new Error("The --schema is required. or pass --config ./fake-server.config.js to load the config file.");
|
|
73
|
+
}
|
|
74
|
+
const normalizedConfig = normalizeFakeServerConfig({
|
|
75
|
+
schemaFilePath,
|
|
76
|
+
logLevel,
|
|
77
|
+
});
|
|
78
|
+
validateFakeServerConfig(normalizedConfig);
|
|
79
|
+
return normalizedConfig;
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAiEzC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,MAAwB,EAA4B,EAAE;IAC5F,OAAO;QACH,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,KAAK,EAAE;YACH,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,UAAU,IAAI,IAAI;YAC5C,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,YAAY,IAAI,IAAI;SACnD;QACD,sBAAsB,EAAE,MAAM,CAAC,sBAAsB,IAAI,IAAI;QAC7D,sBAAsB,EAAE,MAAM,CAAC,sBAAsB,IAAI,CAAC;QAC1D,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,CAAC;QACxC,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,EAAE;QACzC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM;KACtC,CAAC;AACN,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAwB,EAAoB,EAAE;IACnF,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC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,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnF,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC3B,GAAW,EACX,UAAkB,EACe,EAAE;IACnC,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;IAClE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAC3D,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;IAC3C,OAAO,gBAAgB,CAAC;AAC5B,CAAC,CAAC;AACF;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EACxC,cAAc,EACd,QAAQ,GAIX,EAA4B,EAAE;IAC3B,IAAI,CAAC,cAAc,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACX,6FAA6F,CAChG,CAAC;IACN,CAAC;IACD,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;QAC/C,cAAc;QACd,QAAQ;KACX,CAAC,CAAC;IACH,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;IAC3C,OAAO,gBAAgB,CAAC;AAC5B,CAAC,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { createFakeServer } from "./server.js";
|
|
2
2
|
export type { CreateFakeServerOptions } from "./server.js";
|
|
3
|
+
export type { FakeServerConfig, RequiredFakeServerConfig, } from "./config.js";
|
|
4
|
+
export { normalizeFakeServerConfig, validateFakeServerConfig } from "./config.js";
|
|
3
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EACR,gBAAgB,EAChB,wBAAwB,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAM/C,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/esm/server.d.ts
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { type MockObject } from "@newmo/graphql-fake-core";
|
|
2
2
|
import type { GraphQLSchema } from "graphql/index.js";
|
|
3
|
+
import type { RequiredFakeServerConfig } from "./config.js";
|
|
3
4
|
import { type LogLevel } from "./logger.js";
|
|
4
|
-
export type CreateFakeServerOptions = {
|
|
5
|
-
schemaFilePath: string;
|
|
6
|
-
ports?: {
|
|
7
|
-
fakeServer: number;
|
|
8
|
-
apolloServer: number;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* max query depth for complexity of query
|
|
12
|
-
* Default is 3
|
|
13
|
-
*/
|
|
14
|
-
maxQueryDepth?: number;
|
|
15
|
-
/**
|
|
16
|
-
* maxFieldRecursionDepth for creating fake data
|
|
17
|
-
* Default is maxDepth + 1
|
|
18
|
-
*/
|
|
19
|
-
maxFieldRecursionDepth?: number;
|
|
20
|
-
/**
|
|
21
|
-
* max number of registered sequences
|
|
22
|
-
* Default is 1000
|
|
23
|
-
* If the number of registered sequences exceeds this number, the oldest sequence is deleted.
|
|
24
|
-
*/
|
|
25
|
-
maxRegisteredSequences?: number;
|
|
5
|
+
export type CreateFakeServerOptions = RequiredFakeServerConfig & {
|
|
26
6
|
logLevel?: LogLevel;
|
|
27
7
|
};
|
|
28
8
|
type FakeServerInternal = {
|
package/dist/esm/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,0BAA0B,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAItD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,0BAA0B,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAItD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,KAAK,QAAQ,EAAgB,MAAM,aAAa,CAAC;AAE1D,MAAM,MAAM,uBAAuB,GAAG,wBAAwB,GAAG;IAC7D,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACvB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACtB,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE;QACH,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,QAAQ,EAAE,QAAQ,CAAC;CACtB,CAAC;AAiBF,MAAM,MAAM,4BAA4B,GAAG;IACvC,IAAI,EAAE,eAAe,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CACrC,CAAC;AACF,MAAM,MAAM,yBAAyB,GAAG;IACpC,IAAI,EAAE,WAAW,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,GAAG,yBAAyB,CAAC;AAC/F,MAAM,MAAM,yBAAyB,GAC/B;IACI,EAAE,EAAE,IAAI,CAAC;CACZ,GACD;IACI,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AA6PR,eAAO,MAAM,gBAAgB,YAAmB,uBAAuB;;;;;;;;EAkCtE,CAAC;AAEF,eAAO,MAAM,wBAAwB,YAAmB,kBAAkB;;;;;;;;EA6BzE,CAAC"}
|
package/dist/esm/server.js
CHANGED
|
@@ -238,11 +238,13 @@ const createRoutingServer = async ({ logLevel, ports, maxRegisteredSequences, })
|
|
|
238
238
|
return app;
|
|
239
239
|
};
|
|
240
240
|
export const createFakeServer = async (options) => {
|
|
241
|
-
const
|
|
242
|
-
const
|
|
241
|
+
const { logLevel, maxFieldRecursionDepth, maxQueryDepth, maxRegisteredSequences, ports, schemaFilePath, defaultValues, } = options;
|
|
242
|
+
const logger = createLogger(logLevel);
|
|
243
|
+
const schema = buildSchema(await fs.readFile(schemaFilePath, "utf-8"));
|
|
243
244
|
const mockResult = await createMock({
|
|
244
245
|
schema,
|
|
245
|
-
maxFieldRecursionDepth
|
|
246
|
+
maxFieldRecursionDepth,
|
|
247
|
+
defaultValues,
|
|
246
248
|
});
|
|
247
249
|
if (!mockResult.ok) {
|
|
248
250
|
logger.error("Failed to create mock data", mockResult);
|
|
@@ -252,13 +254,6 @@ export const createFakeServer = async (options) => {
|
|
|
252
254
|
}
|
|
253
255
|
logger.debug("created mock code", mockResult.code);
|
|
254
256
|
logger.debug("created mock data", mockResult.mock);
|
|
255
|
-
const ports = {
|
|
256
|
-
fakeServer: options.ports?.fakeServer ?? 4000,
|
|
257
|
-
apolloServer: options.ports?.apolloServer ?? 4001,
|
|
258
|
-
};
|
|
259
|
-
const maxQueryDepth = options.maxQueryDepth ?? 3;
|
|
260
|
-
const maxFieldRecursionDepth = options.maxFieldRecursionDepth ?? maxQueryDepth + 1;
|
|
261
|
-
const maxRegisteredSequences = options.maxRegisteredSequences ?? 1000;
|
|
262
257
|
return createFakeServerInternal({
|
|
263
258
|
ports,
|
|
264
259
|
schema,
|
|
@@ -266,7 +261,7 @@ export const createFakeServer = async (options) => {
|
|
|
266
261
|
maxQueryDepth,
|
|
267
262
|
maxFieldRecursionDepth,
|
|
268
263
|
maxRegisteredSequences,
|
|
269
|
-
logLevel:
|
|
264
|
+
logLevel: logLevel ?? "info",
|
|
270
265
|
});
|
|
271
266
|
};
|
|
272
267
|
export const createFakeServerInternal = async (options) => {
|
package/dist/esm/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAA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,GAAG,EAAE;YACP,YAAY,CAAC,IAAI,EAAE,CAAC;YACpB,YAAY,EAAE,KAAK,EAAE,CAAC;QAC1B,CAAC;KACJ,CAAC;AACN,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newmo/graphql-fake-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "GraphQL fake server for testing",
|
|
6
6
|
"keywords": [
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@graphql-tools/mock": "^9.0.2",
|
|
52
52
|
"@graphql-tools/schema": "^10.0.3",
|
|
53
53
|
"@hono/node-server": "^1.11.1",
|
|
54
|
-
"@newmo/graphql-fake-core": "0.
|
|
54
|
+
"@newmo/graphql-fake-core": "0.10.0",
|
|
55
55
|
"graphql-depth-limit": "^1.1.0",
|
|
56
56
|
"hono": "^4.3.2"
|
|
57
57
|
},
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"access": "public",
|
|
78
78
|
"registry": "https://registry.npmjs.org/"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "37809a1e1d3fca909150d74990d56a0cd8118b9f"
|
|
81
81
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
+
import {
|
|
4
|
+
loadConfig,
|
|
5
|
+
loadFakeServerConfigFromCLI,
|
|
6
|
+
normalizeFakeServerConfig,
|
|
7
|
+
validateFakeServerConfig,
|
|
8
|
+
} from "./config.js";
|
|
3
9
|
import { createFakeServer } from "./index.js";
|
|
4
10
|
import { type LogLevel, createLogger } from "./logger.js";
|
|
5
11
|
|
|
@@ -8,44 +14,35 @@ Usage: npx @newmo/graphql-fake-server --schema <path> [options]
|
|
|
8
14
|
|
|
9
15
|
Options:
|
|
10
16
|
|
|
11
|
-
--
|
|
12
|
-
--
|
|
17
|
+
--config <path> Path to a config file
|
|
18
|
+
--schema <path> Path to a schema file
|
|
13
19
|
--logLevel <logLevel> log level: debug, info, warn, error
|
|
20
|
+
--cwd <path> Current working directory
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
|
|
24
|
+
# Provide a schema file - use default config
|
|
25
|
+
npx @newmo/graphql-fake-server --schema api.graphql
|
|
26
|
+
# Use a config file
|
|
27
|
+
npx @newmo/graphql-fake-server --config graphql-fake-server.config.js
|
|
14
28
|
|
|
15
29
|
`;
|
|
16
30
|
// cli foo.graphql
|
|
17
31
|
export const cli = parseArgs({
|
|
18
32
|
args: process.argv.slice(2),
|
|
19
33
|
options: {
|
|
20
|
-
|
|
21
|
-
schema: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: "Path to the schema file. e.g. schema.graphql",
|
|
24
|
-
},
|
|
25
|
-
mainPort: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Port to run the server on",
|
|
28
|
-
default: "4000",
|
|
29
|
-
},
|
|
30
|
-
apolloPort: {
|
|
31
|
-
type: "string",
|
|
32
|
-
description: "Port to run the server on",
|
|
33
|
-
default: "4002",
|
|
34
|
-
},
|
|
35
|
-
maxRegisteredSequences: {
|
|
34
|
+
cwd: {
|
|
36
35
|
type: "string",
|
|
37
|
-
description: "
|
|
38
|
-
default:
|
|
36
|
+
description: "Current working directory",
|
|
37
|
+
default: process.cwd(),
|
|
39
38
|
},
|
|
40
|
-
|
|
39
|
+
schema: {
|
|
41
40
|
type: "string",
|
|
42
|
-
description: "
|
|
43
|
-
default: "3",
|
|
41
|
+
description: "Path to a schema file",
|
|
44
42
|
},
|
|
45
|
-
|
|
43
|
+
config: {
|
|
46
44
|
type: "string",
|
|
47
|
-
description: "
|
|
48
|
-
default: "4",
|
|
45
|
+
description: "Path to a config file",
|
|
49
46
|
},
|
|
50
47
|
logLevel: {
|
|
51
48
|
type: "string",
|
|
@@ -70,71 +67,18 @@ export const run = async ({
|
|
|
70
67
|
exitCode: 1,
|
|
71
68
|
};
|
|
72
69
|
}
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const mainPort = values.mainPort ? Number.parseInt(values.mainPort, 10) : Number.NaN;
|
|
84
|
-
const apolloPort = values.apolloPort ? Number.parseInt(values.apolloPort, 10) : Number.NaN;
|
|
85
|
-
if (Number.isNaN(mainPort) || Number.isNaN(apolloPort)) {
|
|
86
|
-
logger.info(HELP);
|
|
87
|
-
return {
|
|
88
|
-
stdout: "",
|
|
89
|
-
stderr: "port must be a number",
|
|
90
|
-
exitCode: 1,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const maxFieldRecursionDepth = values.maxFieldRecursionDepth
|
|
94
|
-
? Number.parseInt(values.maxFieldRecursionDepth, 10)
|
|
95
|
-
: Number.NaN;
|
|
96
|
-
if (Number.isNaN(maxFieldRecursionDepth)) {
|
|
97
|
-
logger.info(HELP);
|
|
98
|
-
return {
|
|
99
|
-
stdout: "",
|
|
100
|
-
stderr: "maxFieldRecursionDepth must be a number",
|
|
101
|
-
exitCode: 1,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
const maxQueryDepth = values.maxQueryDepth
|
|
105
|
-
? Number.parseInt(values.maxQueryDepth, 10)
|
|
106
|
-
: Number.NaN;
|
|
107
|
-
if (Number.isNaN(maxQueryDepth)) {
|
|
108
|
-
logger.info(HELP);
|
|
109
|
-
return {
|
|
110
|
-
stdout: "",
|
|
111
|
-
stderr: "maxQueryDepth must be a number",
|
|
112
|
-
exitCode: 1,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
const maxRegisteredSequences = values.maxRegisteredSequences
|
|
116
|
-
? Number.parseInt(values.maxRegisteredSequences, 10)
|
|
117
|
-
: Number.NaN;
|
|
118
|
-
if (Number.isNaN(maxRegisteredSequences)) {
|
|
119
|
-
logger.info(HELP);
|
|
120
|
-
return {
|
|
121
|
-
stdout: "",
|
|
122
|
-
stderr: "maxRegisteredSequences must be a number",
|
|
123
|
-
exitCode: 1,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
70
|
+
const schemaFilePath = values.schema;
|
|
71
|
+
// prefer config file over CLI options
|
|
72
|
+
const config = values.config
|
|
73
|
+
? await loadConfig(values.cwd ?? process.cwd(), values.config)
|
|
74
|
+
: loadFakeServerConfigFromCLI({
|
|
75
|
+
schemaFilePath,
|
|
76
|
+
logLevel,
|
|
77
|
+
});
|
|
78
|
+
const logger = createLogger(config.logLevel ?? logLevel);
|
|
79
|
+
logger.debug("[fake-server-cli] config", config);
|
|
126
80
|
try {
|
|
127
|
-
const server = await createFakeServer(
|
|
128
|
-
schemaFilePath: schemaPath,
|
|
129
|
-
maxRegisteredSequences,
|
|
130
|
-
maxFieldRecursionDepth,
|
|
131
|
-
maxQueryDepth,
|
|
132
|
-
logLevel,
|
|
133
|
-
ports: {
|
|
134
|
-
fakeServer: mainPort,
|
|
135
|
-
apolloServer: apolloPort,
|
|
136
|
-
},
|
|
137
|
-
});
|
|
81
|
+
const server = await createFakeServer(config);
|
|
138
82
|
const { urls } = await server.start();
|
|
139
83
|
logger.info(`🚀 GraphQL Fake Server listening at: ${urls.fakeServer}`);
|
|
140
84
|
return {
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import type { RawConfig } from "@newmo/graphql-fake-core";
|
|
4
|
+
import { configDefaults } from "vitest/config";
|
|
5
|
+
import type { LogLevel } from "./logger.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for the fake server.
|
|
9
|
+
*/
|
|
10
|
+
export type FakeServerConfig = {
|
|
11
|
+
/**
|
|
12
|
+
* The path to the GraphQL schema file.
|
|
13
|
+
*/
|
|
14
|
+
schemaFilePath: string;
|
|
15
|
+
ports?:
|
|
16
|
+
| {
|
|
17
|
+
/**
|
|
18
|
+
* Fake Server port.
|
|
19
|
+
* Default is 4000.
|
|
20
|
+
*/
|
|
21
|
+
fakeServer?: number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Apollo Server port.
|
|
24
|
+
* It provides the GraphQL Playground.
|
|
25
|
+
* Default is 4002.
|
|
26
|
+
*/
|
|
27
|
+
apolloServer?: number | undefined;
|
|
28
|
+
}
|
|
29
|
+
| undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The maximum number of registered sequences.
|
|
32
|
+
* Default is 1000.
|
|
33
|
+
*/
|
|
34
|
+
maxRegisteredSequences?: number | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The maximum number of depth of field recursion.
|
|
37
|
+
* Default is 3.
|
|
38
|
+
*/
|
|
39
|
+
maxFieldRecursionDepth?: RawConfig["maxFieldRecursionDepth"] | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The maximum number of depth of complexity of query
|
|
42
|
+
* Default is 4
|
|
43
|
+
*/
|
|
44
|
+
maxQueryDepth?: number | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Default values for scalar types.
|
|
47
|
+
*/
|
|
48
|
+
defaultValues?: RawConfig["defaultValues"] | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Log level.
|
|
51
|
+
*/
|
|
52
|
+
logLevel?: LogLevel | undefined;
|
|
53
|
+
};
|
|
54
|
+
export type RequiredFakeServerConfig = {
|
|
55
|
+
schemaFilePath: string;
|
|
56
|
+
ports: {
|
|
57
|
+
fakeServer: number;
|
|
58
|
+
apolloServer: number;
|
|
59
|
+
};
|
|
60
|
+
maxRegisteredSequences: number;
|
|
61
|
+
maxFieldRecursionDepth: number;
|
|
62
|
+
maxQueryDepth: number;
|
|
63
|
+
defaultValues: RawConfig["defaultValues"];
|
|
64
|
+
logLevel: LogLevel;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const normalizeFakeServerConfig = (config: FakeServerConfig): RequiredFakeServerConfig => {
|
|
68
|
+
return {
|
|
69
|
+
schemaFilePath: config.schemaFilePath,
|
|
70
|
+
ports: {
|
|
71
|
+
fakeServer: config.ports?.fakeServer ?? 4000,
|
|
72
|
+
apolloServer: config.ports?.apolloServer ?? 4002,
|
|
73
|
+
},
|
|
74
|
+
maxRegisteredSequences: config.maxRegisteredSequences ?? 1000,
|
|
75
|
+
maxFieldRecursionDepth: config.maxFieldRecursionDepth ?? 3,
|
|
76
|
+
maxQueryDepth: config.maxQueryDepth ?? 4,
|
|
77
|
+
defaultValues: config.defaultValues ?? {},
|
|
78
|
+
logLevel: config.logLevel ?? "info",
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export const validateFakeServerConfig = (config: FakeServerConfig): FakeServerConfig => {
|
|
82
|
+
if (!config.schemaFilePath) {
|
|
83
|
+
throw new Error("The schemaFilePath is required.");
|
|
84
|
+
}
|
|
85
|
+
if (typeof config.schemaFilePath !== "string") {
|
|
86
|
+
throw new Error("The schemaPath must be a string.");
|
|
87
|
+
}
|
|
88
|
+
if (config.ports) {
|
|
89
|
+
if (typeof config.ports !== "object") {
|
|
90
|
+
throw new Error("The ports must be an object.");
|
|
91
|
+
}
|
|
92
|
+
if (config.ports.fakeServer && typeof config.ports.fakeServer !== "number") {
|
|
93
|
+
throw new Error("The fakeServer port must be a number.");
|
|
94
|
+
}
|
|
95
|
+
if (config.ports.apolloServer && typeof config.ports.apolloServer !== "number") {
|
|
96
|
+
throw new Error("The apolloServer port must be a number.");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (config.maxRegisteredSequences && typeof config.maxRegisteredSequences !== "number") {
|
|
100
|
+
throw new Error("The maxRegisteredSequences must be a number.");
|
|
101
|
+
}
|
|
102
|
+
if (config.maxFieldRecursionDepth && typeof config.maxFieldRecursionDepth !== "number") {
|
|
103
|
+
throw new Error("The maxFieldRecursionDepth must be a number.");
|
|
104
|
+
}
|
|
105
|
+
if (config.maxQueryDepth && typeof config.maxQueryDepth !== "number") {
|
|
106
|
+
throw new Error("The maxQueryDepth must be a number.");
|
|
107
|
+
}
|
|
108
|
+
if (config.defaultValues) {
|
|
109
|
+
if (typeof config.defaultValues !== "object") {
|
|
110
|
+
throw new Error("The defaultValues must be an object.");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// ["debug", "info", "warn", "error"].includes(logLevel)
|
|
114
|
+
if (config.logLevel && !["debug", "info", "warn", "error"].includes(config.logLevel)) {
|
|
115
|
+
throw new Error("The logLevel must be one of 'debug', 'info', 'warn', 'error'.");
|
|
116
|
+
}
|
|
117
|
+
return config;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Load the fake server configuration from the file.
|
|
122
|
+
* @param configPath
|
|
123
|
+
*/
|
|
124
|
+
export const loadConfig = async (
|
|
125
|
+
cwd: string,
|
|
126
|
+
configPath: string,
|
|
127
|
+
): Promise<RequiredFakeServerConfig> => {
|
|
128
|
+
const fileUrl = pathToFileURL(path.resolve(cwd, configPath)).href;
|
|
129
|
+
const { default: config } = await import(fileUrl);
|
|
130
|
+
const normalizedConfig = normalizeFakeServerConfig(config);
|
|
131
|
+
validateFakeServerConfig(normalizedConfig);
|
|
132
|
+
return normalizedConfig;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Load the fake server configuration from the CLI flags.
|
|
136
|
+
* @param cliFlag
|
|
137
|
+
*/
|
|
138
|
+
export const loadFakeServerConfigFromCLI = ({
|
|
139
|
+
schemaFilePath,
|
|
140
|
+
logLevel,
|
|
141
|
+
}: {
|
|
142
|
+
schemaFilePath?: string | undefined;
|
|
143
|
+
logLevel?: LogLevel | undefined;
|
|
144
|
+
}): RequiredFakeServerConfig => {
|
|
145
|
+
if (!schemaFilePath) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
"The --schema is required. or pass --config ./fake-server.config.js to load the config file.",
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const normalizedConfig = normalizeFakeServerConfig({
|
|
151
|
+
schemaFilePath,
|
|
152
|
+
logLevel,
|
|
153
|
+
});
|
|
154
|
+
validateFakeServerConfig(normalizedConfig);
|
|
155
|
+
return normalizedConfig;
|
|
156
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export { createFakeServer } from "./server.js";
|
|
2
2
|
export type { CreateFakeServerOptions } from "./server.js";
|
|
3
|
+
export type {
|
|
4
|
+
FakeServerConfig,
|
|
5
|
+
RequiredFakeServerConfig,
|
|
6
|
+
} from "./config.js";
|
|
7
|
+
export { normalizeFakeServerConfig, validateFakeServerConfig } from "./config.js";
|
package/src/server.ts
CHANGED
|
@@ -11,30 +11,10 @@ import type { GraphQLSchema } from "graphql/index.js";
|
|
|
11
11
|
import { buildSchema } from "graphql/utilities/index.js";
|
|
12
12
|
import { type Context, Hono } from "hono";
|
|
13
13
|
import { cors } from "hono/cors";
|
|
14
|
+
import type { RequiredFakeServerConfig } from "./config.js";
|
|
14
15
|
import { type LogLevel, createLogger } from "./logger.js";
|
|
15
16
|
|
|
16
|
-
export type CreateFakeServerOptions = {
|
|
17
|
-
schemaFilePath: string;
|
|
18
|
-
ports?: {
|
|
19
|
-
fakeServer: number;
|
|
20
|
-
apolloServer: number;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* max query depth for complexity of query
|
|
24
|
-
* Default is 3
|
|
25
|
-
*/
|
|
26
|
-
maxQueryDepth?: number;
|
|
27
|
-
/**
|
|
28
|
-
* maxFieldRecursionDepth for creating fake data
|
|
29
|
-
* Default is maxDepth + 1
|
|
30
|
-
*/
|
|
31
|
-
maxFieldRecursionDepth?: number;
|
|
32
|
-
/**
|
|
33
|
-
* max number of registered sequences
|
|
34
|
-
* Default is 1000
|
|
35
|
-
* If the number of registered sequences exceeds this number, the oldest sequence is deleted.
|
|
36
|
-
*/
|
|
37
|
-
maxRegisteredSequences?: number;
|
|
17
|
+
export type CreateFakeServerOptions = RequiredFakeServerConfig & {
|
|
38
18
|
logLevel?: LogLevel;
|
|
39
19
|
};
|
|
40
20
|
|
|
@@ -339,11 +319,21 @@ const createRoutingServer = async ({
|
|
|
339
319
|
return app;
|
|
340
320
|
};
|
|
341
321
|
export const createFakeServer = async (options: CreateFakeServerOptions) => {
|
|
342
|
-
const
|
|
343
|
-
|
|
322
|
+
const {
|
|
323
|
+
logLevel,
|
|
324
|
+
maxFieldRecursionDepth,
|
|
325
|
+
maxQueryDepth,
|
|
326
|
+
maxRegisteredSequences,
|
|
327
|
+
ports,
|
|
328
|
+
schemaFilePath,
|
|
329
|
+
defaultValues,
|
|
330
|
+
} = options;
|
|
331
|
+
const logger = createLogger(logLevel);
|
|
332
|
+
const schema = buildSchema(await fs.readFile(schemaFilePath, "utf-8"));
|
|
344
333
|
const mockResult = await createMock({
|
|
345
334
|
schema,
|
|
346
|
-
maxFieldRecursionDepth
|
|
335
|
+
maxFieldRecursionDepth,
|
|
336
|
+
defaultValues,
|
|
347
337
|
});
|
|
348
338
|
if (!mockResult.ok) {
|
|
349
339
|
logger.error("Failed to create mock data", mockResult);
|
|
@@ -353,13 +343,6 @@ export const createFakeServer = async (options: CreateFakeServerOptions) => {
|
|
|
353
343
|
}
|
|
354
344
|
logger.debug("created mock code", mockResult.code);
|
|
355
345
|
logger.debug("created mock data", mockResult.mock);
|
|
356
|
-
const ports = {
|
|
357
|
-
fakeServer: options.ports?.fakeServer ?? 4000,
|
|
358
|
-
apolloServer: options.ports?.apolloServer ?? 4001,
|
|
359
|
-
};
|
|
360
|
-
const maxQueryDepth = options.maxQueryDepth ?? 3;
|
|
361
|
-
const maxFieldRecursionDepth = options.maxFieldRecursionDepth ?? maxQueryDepth + 1;
|
|
362
|
-
const maxRegisteredSequences = options.maxRegisteredSequences ?? 1000;
|
|
363
346
|
return createFakeServerInternal({
|
|
364
347
|
ports,
|
|
365
348
|
schema,
|
|
@@ -367,7 +350,7 @@ export const createFakeServer = async (options: CreateFakeServerOptions) => {
|
|
|
367
350
|
maxQueryDepth,
|
|
368
351
|
maxFieldRecursionDepth,
|
|
369
352
|
maxRegisteredSequences,
|
|
370
|
-
logLevel:
|
|
353
|
+
logLevel: logLevel ?? "info",
|
|
371
354
|
});
|
|
372
355
|
};
|
|
373
356
|
|