@ldsg/graphql 0.1.0-alpha.19 → 0.2.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/dist/__tests__/e2e.d.ts +2 -0
- package/dist/__tests__/e2e.d.ts.map +1 -0
- package/dist/__tests__/e2e.js +34 -0
- package/dist/__tests__/unit.d.ts +2 -0
- package/dist/__tests__/unit.d.ts.map +1 -0
- package/dist/__tests__/unit.js +56 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -3
- package/dist/resource.d.ts +3 -0
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +25 -14
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/modify-graphql-schema.d.ts +3 -0
- package/dist/types/modify-graphql-schema.d.ts.map +1 -0
- package/dist/types/modify-graphql-schema.js +2 -0
- package/dist/types/schema-composer-params.d.ts +5 -0
- package/dist/types/schema-composer-params.d.ts.map +1 -0
- package/dist/types/schema-composer-params.js +2 -0
- package/package.json +8 -6
- package/dist/resource.spec.d.ts +0 -2
- package/dist/resource.spec.d.ts.map +0 -1
- package/dist/resource.spec.js +0 -46
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e2e.d.ts","sourceRoot":"","sources":["../../src/__tests__/e2e.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const application_1 = require("@ldsg/application");
|
|
7
|
+
const supertest_1 = __importDefault(require("supertest"));
|
|
8
|
+
const resource_1 = require("../resource");
|
|
9
|
+
test("e2e", async () => {
|
|
10
|
+
const applicationResource = new application_1.ApplicationResource({
|
|
11
|
+
id: "application",
|
|
12
|
+
kind: "application",
|
|
13
|
+
parentId: "ROOT",
|
|
14
|
+
settings: {
|
|
15
|
+
title: "应用",
|
|
16
|
+
description: "应用根资源",
|
|
17
|
+
name: "测试应用",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
new resource_1.GraphqlResource({
|
|
21
|
+
id: "graphql",
|
|
22
|
+
kind: "graphql",
|
|
23
|
+
parentId: "application",
|
|
24
|
+
settings: {
|
|
25
|
+
title: "",
|
|
26
|
+
description: "",
|
|
27
|
+
graphqlEndpoint: "/test-graphql",
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const app = applicationResource.createExpressApp();
|
|
31
|
+
const response = await (0, supertest_1.default)(app).get("/test-graphql");
|
|
32
|
+
expect(response.statusCode).toBe(200);
|
|
33
|
+
expect(response.text).toMatchSnapshot();
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../../src/__tests__/unit.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const resource_1 = require("@ldsg/resource");
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const resource_2 = require("../resource");
|
|
6
|
+
test("unit", () => {
|
|
7
|
+
const graphqlResource = new resource_2.GraphqlResource({
|
|
8
|
+
id: "test-graphql",
|
|
9
|
+
kind: "graphql",
|
|
10
|
+
parentId: "test-application",
|
|
11
|
+
settings: {
|
|
12
|
+
title: "",
|
|
13
|
+
description: "",
|
|
14
|
+
graphqlEndpoint: "/test-graphql",
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
class AResource extends resource_1.Resource {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.modifyGraphQLSchema = (params) => {
|
|
21
|
+
const { schemaComposer } = params;
|
|
22
|
+
const PostTC = schemaComposer.createObjectTC({
|
|
23
|
+
name: "Post",
|
|
24
|
+
fields: {
|
|
25
|
+
id: "Int!",
|
|
26
|
+
title: "String",
|
|
27
|
+
votes: "Int",
|
|
28
|
+
authorId: "Int",
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
schemaComposer.Query.addFields({
|
|
32
|
+
posts: {
|
|
33
|
+
type: "[Post]",
|
|
34
|
+
resolve: () => [
|
|
35
|
+
{ id: 1, authorId: 1, title: "Introduction to GraphQL", votes: 2 },
|
|
36
|
+
{ id: 2, authorId: 2, title: "Welcome to Apollo", votes: 3 },
|
|
37
|
+
{ id: 3, authorId: 2, title: "Advanced GraphQL", votes: 1 },
|
|
38
|
+
{ id: 4, authorId: 3, title: "Launchpad is Cool", votes: 7 },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
new AResource({
|
|
46
|
+
id: "test-a",
|
|
47
|
+
kind: "a",
|
|
48
|
+
parentId: "test-application",
|
|
49
|
+
settings: {
|
|
50
|
+
title: "",
|
|
51
|
+
description: "",
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const { schema } = graphqlResource.getGraphQLSchema();
|
|
55
|
+
expect((0, graphql_1.printSchema)(schema)).toMatchSnapshot();
|
|
56
|
+
});
|
package/dist/constants.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ export declare const HANDLER_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
|
|
|
10
10
|
export declare const HANDLER_SPECIFIC_RESOURCE_SETTINGS: HandlerSpecificResourceSettings;
|
|
11
11
|
export declare const RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
|
|
12
12
|
export declare const RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS: ResourceDefinitionSpecificResourceSettings;
|
|
13
|
+
export declare const DEFAULT_GRAPHQL_ENDPOINT = "/graphql";
|
|
13
14
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,iCAAiC,EAAE,uBAG/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,EAAE,+BAQ9C,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBACf,CAAC;AAE9C,eAAO,MAAM,8CAA8C,EAAE,0CAI1D,CAAC;AAEJ,eAAO,MAAM,wBAAwB,aAAa,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
|
|
3
|
+
exports.DEFAULT_GRAPHQL_ENDPOINT = exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
|
|
4
|
+
const application_1 = require("@ldsg/application");
|
|
4
5
|
exports.HANDLER_GENERAL_RESOURCE_SETTINGS = {
|
|
5
6
|
title: "GraphQL类型资源处理程序",
|
|
6
7
|
description: "",
|
|
@@ -20,6 +21,7 @@ exports.HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
|
|
|
20
21
|
};
|
|
21
22
|
exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = { title: "GraphQL类型资源定义", description: "" };
|
|
22
23
|
exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
|
|
23
|
-
kind: "
|
|
24
|
-
|
|
24
|
+
kind: "graphql",
|
|
25
|
+
parentKind: application_1.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS.kind,
|
|
25
26
|
};
|
|
27
|
+
exports.DEFAULT_GRAPHQL_ENDPOINT = "/graphql";
|
package/dist/resource.d.ts
CHANGED
|
@@ -3,5 +3,8 @@ import { Resource } from "@ldsg/resource";
|
|
|
3
3
|
import { GraphqlSpecificResourceSettings } from "./types";
|
|
4
4
|
export declare class GraphqlResource extends Resource<GraphqlSpecificResourceSettings> {
|
|
5
5
|
extendExpressApp: ExtendExpressApp;
|
|
6
|
+
getGraphQLSchema: () => {
|
|
7
|
+
schema: import("graphql").GraphQLSchema;
|
|
8
|
+
};
|
|
6
9
|
}
|
|
7
10
|
//# sourceMappingURL=resource.d.ts.map
|
package/dist/resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C,OAAO,EAAE,+BAA+B,EAAuB,MAAM,SAAS,CAAC;AAE/E,qBAAa,eAAgB,SAAQ,QAAQ,CAAC,+BAA+B,CAAC;IAC5E,gBAAgB,EAAE,gBAAgB,CAehC;IAEF,gBAAgB;;MAwBd;CACH"}
|
package/dist/resource.js
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.GraphqlResource = void 0;
|
|
13
4
|
const resource_1 = require("@ldsg/resource");
|
|
5
|
+
const graphql_compose_1 = require("graphql-compose");
|
|
14
6
|
const graphql_yoga_1 = require("graphql-yoga");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
15
8
|
class GraphqlResource extends resource_1.Resource {
|
|
16
9
|
constructor() {
|
|
17
10
|
super(...arguments);
|
|
18
|
-
this.extendExpressApp = (params) =>
|
|
11
|
+
this.extendExpressApp = async (params) => {
|
|
19
12
|
const { app } = params;
|
|
20
|
-
const { graphqlEndpoint } = this
|
|
13
|
+
const { settings: { graphqlEndpoint = constants_1.DEFAULT_GRAPHQL_ENDPOINT }, } = this;
|
|
14
|
+
const { schema } = this.getGraphQLSchema();
|
|
21
15
|
const yoga = (0, graphql_yoga_1.createYoga)({
|
|
22
16
|
graphqlEndpoint,
|
|
17
|
+
schema,
|
|
23
18
|
});
|
|
24
19
|
app.use(yoga.graphqlEndpoint, yoga);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
};
|
|
21
|
+
this.getGraphQLSchema = () => {
|
|
22
|
+
const schemaComposer = new graphql_compose_1.SchemaComposer();
|
|
23
|
+
const { parentId, getFilteredResources } = this;
|
|
24
|
+
const { resources } = getFilteredResources({
|
|
25
|
+
parentId,
|
|
26
|
+
});
|
|
27
|
+
resources.forEach((resource) => {
|
|
28
|
+
var _a;
|
|
29
|
+
(_a = resource.modifyGraphQLSchema) === null || _a === void 0 ? void 0 : _a.call(resource, {
|
|
30
|
+
schemaComposer,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
const schema = schemaComposer.buildSchema();
|
|
34
|
+
const res = {
|
|
35
|
+
schema,
|
|
36
|
+
};
|
|
37
|
+
return res;
|
|
38
|
+
};
|
|
28
39
|
}
|
|
29
40
|
}
|
|
30
41
|
exports.GraphqlResource = GraphqlResource;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC"}
|
package/dist/types/index.js
CHANGED
|
@@ -14,4 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./modify-graphql-schema"), exports);
|
|
18
|
+
__exportStar(require("./schema-composer-params"), exports);
|
|
17
19
|
__exportStar(require("./specific-resource-settings"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modify-graphql-schema.d.ts","sourceRoot":"","sources":["../../src/types/modify-graphql-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-composer-params.d.ts","sourceRoot":"","sources":["../../src/types/schema-composer-params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,cAAc,CAAC;CAChC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/graphql",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -14,16 +14,18 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"graphql-compose": "^9.1.0",
|
|
17
18
|
"graphql-yoga": "^5.13.4",
|
|
18
|
-
"@ldsg/handler": "0.1
|
|
19
|
-
"@ldsg/resource": "0.1
|
|
20
|
-
"@ldsg/resource-definition": "0.1
|
|
19
|
+
"@ldsg/handler": "0.2.1",
|
|
20
|
+
"@ldsg/resource": "0.2.1",
|
|
21
|
+
"@ldsg/resource-definition": "0.2.1"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@types/supertest": "^6.0.0",
|
|
25
|
+
"graphql": "16.11.0",
|
|
24
26
|
"supertest": "^6.3.4",
|
|
25
|
-
"@ldsg/
|
|
26
|
-
"@ldsg/
|
|
27
|
+
"@ldsg/application": "0.2.1",
|
|
28
|
+
"@ldsg/types": "0.2.1"
|
|
27
29
|
},
|
|
28
30
|
"scripts": {
|
|
29
31
|
"build": "pnpm clean && tsc --project tsconfig.build.json",
|
package/dist/resource.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resource.spec.d.ts","sourceRoot":"","sources":["../src/resource.spec.ts"],"names":[],"mappings":""}
|
package/dist/resource.spec.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const application_1 = require("@ldsg/application");
|
|
16
|
-
const supertest_1 = __importDefault(require("supertest"));
|
|
17
|
-
const resource_1 = require("./resource");
|
|
18
|
-
test("application", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
const applicationResource = new application_1.ApplicationResource({
|
|
20
|
-
id: "application",
|
|
21
|
-
kind: "APPLICATION",
|
|
22
|
-
parentId: "ROOT",
|
|
23
|
-
settings: {
|
|
24
|
-
title: "应用",
|
|
25
|
-
description: "应用根资源",
|
|
26
|
-
name: "测试应用",
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
new resource_1.GraphqlResource({
|
|
30
|
-
id: "graphql",
|
|
31
|
-
kind: "GRAPHQL",
|
|
32
|
-
parentId: "application",
|
|
33
|
-
settings: {
|
|
34
|
-
title: "",
|
|
35
|
-
description: "",
|
|
36
|
-
graphqlEndpoint: "/test-graphql",
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
const app = yield applicationResource.createExpressApp();
|
|
40
|
-
const response = yield (0, supertest_1.default)(app).get("/");
|
|
41
|
-
expect(response.statusCode).toBe(200);
|
|
42
|
-
expect(response.text).toBe("Hello, 测试应用!");
|
|
43
|
-
const response2 = yield (0, supertest_1.default)(app).get("/test-graphql");
|
|
44
|
-
expect(response2.statusCode).toBe(200);
|
|
45
|
-
expect(response2.text).toMatchSnapshot();
|
|
46
|
-
}));
|