nsgm-cli 2.1.3 → 2.1.5
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/generation/tsconfig.json +2 -2
- package/lib/generate.js +0 -2
- package/lib/server/graphql.d.ts +2 -6
- package/lib/server/graphql.js +21 -20
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/next-env.d.ts +1 -1
- package/package.json +49 -48
- package/server/rest.js +1 -1
package/generation/tsconfig.json
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
"target": "ES2022",
|
|
5
5
|
"module": "commonjs",
|
|
6
6
|
"declaration": true,
|
|
7
|
-
"outDir": "./lib",
|
|
8
7
|
"strict": true,
|
|
9
8
|
"lib": [
|
|
10
9
|
"dom",
|
|
@@ -33,7 +32,8 @@
|
|
|
33
32
|
"noFallthroughCasesInSwitch": true
|
|
34
33
|
},
|
|
35
34
|
"include": [
|
|
36
|
-
"
|
|
35
|
+
"client/**/*",
|
|
36
|
+
"pages/**/*"
|
|
37
37
|
],
|
|
38
38
|
"exclude": [
|
|
39
39
|
"node_modules",
|
package/lib/generate.js
CHANGED
|
@@ -116,8 +116,6 @@ const replaceInFileAll = async (array, index = 0, callback) => {
|
|
|
116
116
|
};
|
|
117
117
|
const sourceFolder = __dirname;
|
|
118
118
|
const destFolder = process.cwd();
|
|
119
|
-
console.log('sourceFolder', sourceFolder);
|
|
120
|
-
console.log('destFolder', destFolder);
|
|
121
119
|
const isLocal = sourceFolder === resolve(`${destFolder}/lib`);
|
|
122
120
|
const generationPath = '../generation';
|
|
123
121
|
const clientPathSource = '../client';
|
package/lib/server/graphql.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
|
|
3
|
-
}, response: import("http").ServerResponse<import("http").IncomingMessage> & {
|
|
4
|
-
json?: (data: unknown) => void;
|
|
5
|
-
}) => Promise<void>;
|
|
6
|
-
export default _default;
|
|
1
|
+
declare const handler: (command: string) => import("express").Handler;
|
|
2
|
+
export default handler;
|
package/lib/server/graphql.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const express_1 = require("graphql-http/lib/use/express");
|
|
7
7
|
const graphql_1 = require("graphql");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -150,33 +150,34 @@ function generateTypeDefsAndResolvers() {
|
|
|
150
150
|
}
|
|
151
151
|
const generateResult = generateTypeDefsAndResolvers();
|
|
152
152
|
const { querySchemes: querySchemesV, mutationSchemes: mutationSchemesV, subscriptionSchemes: subscriptionSchemesV, typeSchemes: typeSchemesV, resolvers: resolversV, scalarStr: scalarStrV, schemaStr: generatedSchemaStr } = generateResult;
|
|
153
|
-
//
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
// 导出 handler 函数,兼容 express 用法
|
|
154
|
+
const handler = (command) => {
|
|
155
|
+
const schemaStr = generatedSchemaStr ||
|
|
156
|
+
`
|
|
157
|
+
${scalarStrV}
|
|
157
158
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
type Query {
|
|
160
|
+
${querySchemesV?.join('\n') || '_: Boolean'}
|
|
161
|
+
}
|
|
161
162
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
type Mutation {
|
|
164
|
+
${mutationSchemesV?.join('\n') || '_: Boolean'}
|
|
165
|
+
}
|
|
165
166
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
type Subscription {
|
|
168
|
+
${subscriptionSchemesV?.join('\n') || '_: Boolean'}
|
|
169
|
+
}
|
|
169
170
|
|
|
170
|
-
|
|
171
|
-
`;
|
|
172
|
-
exports.default = (command) => {
|
|
171
|
+
${typeSchemesV?.join('\n') || ''}
|
|
172
|
+
`;
|
|
173
173
|
if (command === 'dev') {
|
|
174
174
|
console.log('schemaStr', schemaStr);
|
|
175
175
|
console.log('resolvers', resolversV);
|
|
176
176
|
}
|
|
177
|
-
|
|
177
|
+
// graphql-http 不再内置 graphiql,需手动集成 playground 或 altair,以下为基础 handler
|
|
178
|
+
return (0, express_1.createHandler)({
|
|
178
179
|
schema: (0, graphql_1.buildSchema)(schemaStr),
|
|
179
|
-
rootValue: resolversV
|
|
180
|
-
graphiql: true
|
|
180
|
+
rootValue: resolversV
|
|
181
181
|
});
|
|
182
182
|
};
|
|
183
|
+
exports.default = handler;
|