@ldsg/graphql 0.3.30 → 0.3.32
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.js +16 -16
- package/dist/__tests__/unit.js +27 -27
- package/dist/constants.d.ts +3 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +9 -9
- package/dist/handler.d.ts +4 -4
- package/dist/index.d.ts +5 -5
- package/dist/instantiate-resource.d.ts +4 -4
- package/dist/instantiate-resource.js +1 -1
- package/dist/resource.d.ts +3 -3
- package/dist/resource.js +10 -10
- package/dist/types/graphql-middleware-info.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/modify-graphql-schema.d.ts +1 -1
- package/dist/types/schema-composer-params.d.ts +1 -1
- package/dist/types/specific-resource-settings.d.ts +1 -1
- package/dist/types/specific-resource-settings.js +1 -1
- package/package.json +11 -7
package/dist/__tests__/e2e.js
CHANGED
|
@@ -6,29 +6,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const application_1 = require("@ldsg/application");
|
|
7
7
|
const supertest_1 = __importDefault(require("supertest"));
|
|
8
8
|
const resource_1 = require("../resource");
|
|
9
|
-
test(
|
|
9
|
+
test("e2e", async () => {
|
|
10
10
|
const applicationResource = new application_1.ApplicationResource({
|
|
11
|
-
id:
|
|
12
|
-
kind:
|
|
13
|
-
parentId:
|
|
11
|
+
id: "application",
|
|
12
|
+
kind: "application",
|
|
13
|
+
parentId: "ROOT",
|
|
14
14
|
settings: {
|
|
15
|
-
title:
|
|
16
|
-
description:
|
|
17
|
-
name:
|
|
18
|
-
}
|
|
15
|
+
title: "应用",
|
|
16
|
+
description: "应用根资源",
|
|
17
|
+
name: "测试应用",
|
|
18
|
+
},
|
|
19
19
|
});
|
|
20
20
|
new resource_1.GraphqlResource({
|
|
21
|
-
id:
|
|
22
|
-
kind:
|
|
23
|
-
parentId:
|
|
21
|
+
id: "graphql",
|
|
22
|
+
kind: "graphql",
|
|
23
|
+
parentId: "application",
|
|
24
24
|
settings: {
|
|
25
|
-
title:
|
|
26
|
-
description:
|
|
27
|
-
graphqlEndpoint:
|
|
28
|
-
}
|
|
25
|
+
title: "",
|
|
26
|
+
description: "",
|
|
27
|
+
graphqlEndpoint: "/test-graphql",
|
|
28
|
+
},
|
|
29
29
|
});
|
|
30
30
|
const app = applicationResource.createExpressApp();
|
|
31
|
-
const response = await (0, supertest_1.default)(app).get(
|
|
31
|
+
const response = await (0, supertest_1.default)(app).get("/test-graphql");
|
|
32
32
|
expect(response.statusCode).toBe(200);
|
|
33
33
|
expect(response.text).toMatchSnapshot();
|
|
34
34
|
});
|
package/dist/__tests__/unit.js
CHANGED
|
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const resource_1 = require("@ldsg/resource");
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const resource_2 = require("../resource");
|
|
6
|
-
test(
|
|
6
|
+
test("unit", () => {
|
|
7
7
|
const graphqlResource = new resource_2.GraphqlResource({
|
|
8
|
-
id:
|
|
9
|
-
kind:
|
|
10
|
-
parentId:
|
|
8
|
+
id: "test-graphql",
|
|
9
|
+
kind: "graphql",
|
|
10
|
+
parentId: "test-application",
|
|
11
11
|
settings: {
|
|
12
|
-
title:
|
|
13
|
-
description:
|
|
14
|
-
graphqlEndpoint:
|
|
15
|
-
}
|
|
12
|
+
title: "",
|
|
13
|
+
description: "",
|
|
14
|
+
graphqlEndpoint: "/test-graphql",
|
|
15
|
+
},
|
|
16
16
|
});
|
|
17
17
|
class AResource extends resource_1.Resource {
|
|
18
18
|
constructor() {
|
|
@@ -20,36 +20,36 @@ test('unit', () => {
|
|
|
20
20
|
this.modifyGraphQLSchema = (params) => {
|
|
21
21
|
const { schemaComposer } = params;
|
|
22
22
|
const PostTC = schemaComposer.createObjectTC({
|
|
23
|
-
name:
|
|
23
|
+
name: "Post",
|
|
24
24
|
fields: {
|
|
25
|
-
id:
|
|
26
|
-
title:
|
|
27
|
-
votes:
|
|
28
|
-
authorId:
|
|
29
|
-
}
|
|
25
|
+
id: "Int!",
|
|
26
|
+
title: "String",
|
|
27
|
+
votes: "Int",
|
|
28
|
+
authorId: "Int",
|
|
29
|
+
},
|
|
30
30
|
});
|
|
31
31
|
schemaComposer.Query.addFields({
|
|
32
32
|
posts: {
|
|
33
|
-
type:
|
|
33
|
+
type: "[Post]",
|
|
34
34
|
resolve: () => [
|
|
35
|
-
{ id: 1, authorId: 1, title:
|
|
36
|
-
{ id: 2, authorId: 2, title:
|
|
37
|
-
{ id: 3, authorId: 2, title:
|
|
38
|
-
{ id: 4, authorId: 3, title:
|
|
39
|
-
]
|
|
40
|
-
}
|
|
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
41
|
});
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
new AResource({
|
|
46
|
-
id:
|
|
47
|
-
kind:
|
|
48
|
-
parentId:
|
|
46
|
+
id: "test-a",
|
|
47
|
+
kind: "a",
|
|
48
|
+
parentId: "test-application",
|
|
49
49
|
settings: {
|
|
50
|
-
title:
|
|
51
|
-
description:
|
|
52
|
-
}
|
|
50
|
+
title: "",
|
|
51
|
+
description: "",
|
|
52
|
+
},
|
|
53
53
|
});
|
|
54
54
|
const { schema } = graphqlResource.getGraphQLSchema();
|
|
55
55
|
expect((0, graphql_1.printSchema)(schema)).toMatchSnapshot();
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HandlerSpecificResourceSettings } from
|
|
2
|
-
import { ResourceDefinitionSpecificResourceSettings } from
|
|
3
|
-
import { GeneralResourceSettings } from
|
|
1
|
+
import { HandlerSpecificResourceSettings } from "@ldsg/handler";
|
|
2
|
+
import { ResourceDefinitionSpecificResourceSettings } from "@ldsg/resource-definition";
|
|
3
|
+
import { GeneralResourceSettings } from "@ldsg/types";
|
|
4
4
|
/**
|
|
5
5
|
* Instantiate Resource Handler General Resource Settings
|
|
6
6
|
* 实例化资源处理程序普通资源配置
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,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;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,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;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAQnE,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAG1D,CAAC;AAEJ,eAAO,MAAM,wBAAwB,aAAa,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -6,8 +6,8 @@ exports.DEFAULT_GRAPHQL_ENDPOINT = exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE
|
|
|
6
6
|
* 实例化资源处理程序普通资源配置
|
|
7
7
|
*/
|
|
8
8
|
exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = {
|
|
9
|
-
title:
|
|
10
|
-
description:
|
|
9
|
+
title: "GraphQL实例化资源处理程序",
|
|
10
|
+
description: "",
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
13
|
* Instantiate Resource Handler Specific Resource Settings
|
|
@@ -18,15 +18,15 @@ exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
|
|
|
18
18
|
code: `export * from "@ldsg/graphql";`,
|
|
19
19
|
dependencies: [
|
|
20
20
|
{
|
|
21
|
-
name:
|
|
22
|
-
}
|
|
23
|
-
]
|
|
21
|
+
name: "@ldsg/graphql",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
24
|
};
|
|
25
25
|
exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
|
|
26
|
-
title:
|
|
27
|
-
description:
|
|
26
|
+
title: "GraphQL资源定义",
|
|
27
|
+
description: "",
|
|
28
28
|
};
|
|
29
29
|
exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
|
|
30
|
-
kind:
|
|
30
|
+
kind: "graphql",
|
|
31
31
|
};
|
|
32
|
-
exports.DEFAULT_GRAPHQL_ENDPOINT =
|
|
32
|
+
exports.DEFAULT_GRAPHQL_ENDPOINT = "/graphql";
|
package/dist/handler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Handler, HandlerExtendedResourceSettings } from
|
|
2
|
-
import { InstantiateResourceParams, InstantiateResourceRes } from
|
|
3
|
-
import { GraphqlResource } from
|
|
4
|
-
import { GraphqlSpecificResourceSettings } from
|
|
1
|
+
import { Handler, HandlerExtendedResourceSettings } from "@ldsg/handler";
|
|
2
|
+
import { InstantiateResourceParams, InstantiateResourceRes } from "@ldsg/resource";
|
|
3
|
+
import { GraphqlResource } from "./resource";
|
|
4
|
+
import { GraphqlSpecificResourceSettings } from "./types";
|
|
5
5
|
export declare const handler: Handler<InstantiateResourceParams<HandlerExtendedResourceSettings<GraphqlSpecificResourceSettings>>, InstantiateResourceRes<GraphqlResource>>;
|
|
6
6
|
//# sourceMappingURL=handler.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./constants";
|
|
2
|
+
export * from "./handler";
|
|
3
|
+
export * from "./instantiate-resource";
|
|
4
|
+
export * from "./resource";
|
|
5
|
+
export * from "./types";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HandlerExtendedResourceSettings } from
|
|
2
|
-
import { InstantiateResource } from
|
|
3
|
-
import { GraphqlResource } from
|
|
4
|
-
import { GraphqlSpecificResourceSettings } from
|
|
1
|
+
import { HandlerExtendedResourceSettings } from "@ldsg/handler";
|
|
2
|
+
import { InstantiateResource } from "@ldsg/resource";
|
|
3
|
+
import { GraphqlResource } from "./resource";
|
|
4
|
+
import { GraphqlSpecificResourceSettings } from "./types";
|
|
5
5
|
export declare const instantiateResource: InstantiateResource<HandlerExtendedResourceSettings<GraphqlSpecificResourceSettings>, GraphqlResource>;
|
|
6
6
|
//# sourceMappingURL=instantiate-resource.d.ts.map
|
package/dist/resource.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExtendExpressApp } from
|
|
2
|
-
import { Resource } from
|
|
3
|
-
import { GraphqlSpecificResourceSettings } from
|
|
1
|
+
import { ExtendExpressApp } from "@ldsg/application";
|
|
2
|
+
import { Resource } from "@ldsg/resource";
|
|
3
|
+
import { GraphqlSpecificResourceSettings } from "./types";
|
|
4
4
|
export declare class GraphqlResource extends Resource<GraphqlSpecificResourceSettings> {
|
|
5
5
|
extendExpressApp: ExtendExpressApp;
|
|
6
6
|
getGraphQLSchema: () => {
|
package/dist/resource.js
CHANGED
|
@@ -13,12 +13,12 @@ class GraphqlResource extends resource_1.Resource {
|
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.extendExpressApp = async (params) => {
|
|
15
15
|
const { app } = params;
|
|
16
|
-
const { settings: { graphqlEndpoint = constants_1.DEFAULT_GRAPHQL_ENDPOINT } } = this;
|
|
16
|
+
const { settings: { graphqlEndpoint = constants_1.DEFAULT_GRAPHQL_ENDPOINT }, } = this;
|
|
17
17
|
const { schema } = this.getGraphQLSchema();
|
|
18
18
|
const lexicographicSortSchemaRes = (0, graphql_1.lexicographicSortSchema)(schema);
|
|
19
19
|
const yoga = (0, graphql_yoga_1.createYoga)({
|
|
20
20
|
graphqlEndpoint,
|
|
21
|
-
schema: lexicographicSortSchemaRes
|
|
21
|
+
schema: lexicographicSortSchemaRes,
|
|
22
22
|
});
|
|
23
23
|
app.use(yoga.graphqlEndpoint, yoga);
|
|
24
24
|
};
|
|
@@ -32,30 +32,30 @@ class GraphqlResource extends resource_1.Resource {
|
|
|
32
32
|
});
|
|
33
33
|
const { id, parentId, getFilteredResources } = this;
|
|
34
34
|
const { resources: peerResources } = getFilteredResources({
|
|
35
|
-
parentId
|
|
35
|
+
parentId,
|
|
36
36
|
});
|
|
37
37
|
const { resources: childResources } = getFilteredResources({
|
|
38
|
-
parentId: id
|
|
38
|
+
parentId: id,
|
|
39
39
|
});
|
|
40
40
|
const allResources = [...peerResources, ...childResources];
|
|
41
41
|
allResources
|
|
42
|
-
.filter((resource) => resource.kind !==
|
|
42
|
+
.filter((resource) => resource.kind !== "graphql_resolvers")
|
|
43
43
|
.forEach((resource) => {
|
|
44
44
|
var _a;
|
|
45
45
|
(_a = resource.modifyGraphQLSchema) === null || _a === void 0 ? void 0 : _a.call(resource, {
|
|
46
|
-
schemaComposer
|
|
46
|
+
schemaComposer,
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
allResources
|
|
50
|
-
.filter((resource) => resource.kind ===
|
|
50
|
+
.filter((resource) => resource.kind === "graphql_resolvers")
|
|
51
51
|
.forEach((resource) => {
|
|
52
52
|
var _a;
|
|
53
53
|
(_a = resource.modifyGraphQLSchema) === null || _a === void 0 ? void 0 : _a.call(resource, {
|
|
54
|
-
schemaComposer
|
|
54
|
+
schemaComposer,
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
const { resources: childMiddlewareResources } = getFilteredResources({
|
|
58
|
-
parentId: id
|
|
58
|
+
parentId: id,
|
|
59
59
|
});
|
|
60
60
|
const graphqlMiddlewareInfos = [];
|
|
61
61
|
childMiddlewareResources.forEach((resource) => {
|
|
@@ -70,7 +70,7 @@ class GraphqlResource extends resource_1.Resource {
|
|
|
70
70
|
const sortedGraphqlMiddlewares = sortedGraphqlMiddlewareInfos.map((sortedGraphqlMiddlewareInfo) => sortedGraphqlMiddlewareInfo.middleware);
|
|
71
71
|
const schemaWithMiddleware = (0, graphql_middleware_1.applyMiddleware)(schema, ...sortedGraphqlMiddlewares);
|
|
72
72
|
const res = {
|
|
73
|
-
schema: schemaWithMiddleware
|
|
73
|
+
schema: schemaWithMiddleware,
|
|
74
74
|
};
|
|
75
75
|
return res;
|
|
76
76
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMiddleware, IMiddlewareGenerator } from
|
|
1
|
+
import { IMiddleware, IMiddlewareGenerator } from "graphql-middleware";
|
|
2
2
|
export interface GraphqlMiddlewareInfo {
|
|
3
3
|
middleware: IMiddleware<any, any, any> | IMiddlewareGenerator<any, any, any>;
|
|
4
4
|
sort: number;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./graphql-middleware-info";
|
|
2
|
+
export * from "./modify-graphql-schema";
|
|
3
|
+
export * from "./schema-composer-params";
|
|
4
|
+
export * from "./specific-resource-settings";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -7,7 +7,7 @@ exports.GraphqlSpecificResourceSettingsSchema = zod_1.z
|
|
|
7
7
|
/**
|
|
8
8
|
* GraphQL Endpoint
|
|
9
9
|
*/
|
|
10
|
-
graphqlEndpoint: zod_1.z.string().optional()
|
|
10
|
+
graphqlEndpoint: zod_1.z.string().optional(),
|
|
11
11
|
})
|
|
12
12
|
.catchall(zod_1.z.any());
|
|
13
13
|
exports.SpecificResourceSettingsSchema = exports.GraphqlSpecificResourceSettingsSchema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/graphql",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,25 +12,27 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"graphql": "16.11.0",
|
|
15
|
-
"graphql-compose": "
|
|
15
|
+
"graphql-compose": "9.1.0",
|
|
16
16
|
"graphql-middleware": "^6.1.35",
|
|
17
17
|
"graphql-scalars": "^1.25.0",
|
|
18
18
|
"graphql-yoga": "^5.13.4",
|
|
19
19
|
"zod": "^4.1.11",
|
|
20
|
-
"@ldsg/handler": "0.3.
|
|
21
|
-
"@ldsg/resource
|
|
22
|
-
"@ldsg/resource": "0.3.
|
|
20
|
+
"@ldsg/handler": "0.3.32",
|
|
21
|
+
"@ldsg/resource": "0.3.32",
|
|
22
|
+
"@ldsg/resource-definition": "0.3.32"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/jest": "^29.5.2",
|
|
26
26
|
"@types/supertest": "^6.0.0",
|
|
27
27
|
"jest": "^29.5.0",
|
|
28
|
+
"oxfmt": "latest",
|
|
29
|
+
"oxlint": "latest",
|
|
28
30
|
"supertest": "^6.3.4",
|
|
29
31
|
"ts-jest": "^29.1.5",
|
|
30
32
|
"ts-node": "^10.9.2",
|
|
31
33
|
"typescript": "^5.8.3",
|
|
32
|
-
"@ldsg/
|
|
33
|
-
"@ldsg/
|
|
34
|
+
"@ldsg/types": "0.3.32",
|
|
35
|
+
"@ldsg/application": "0.3.32"
|
|
34
36
|
},
|
|
35
37
|
"publishConfig": {
|
|
36
38
|
"access": "public"
|
|
@@ -38,6 +40,8 @@
|
|
|
38
40
|
"scripts": {
|
|
39
41
|
"build": "tsc --project tsconfig.build.json",
|
|
40
42
|
"clean": "rm -rf dist",
|
|
43
|
+
"format": "oxfmt --write src/",
|
|
44
|
+
"lint": "oxlint src/",
|
|
41
45
|
"test": "jest"
|
|
42
46
|
}
|
|
43
47
|
}
|