@ldsg/graphql 0.3.9 → 0.3.10

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.
@@ -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("e2e", async () => {
9
+ test('e2e', async () => {
10
10
  const applicationResource = new application_1.ApplicationResource({
11
- id: "application",
12
- kind: "application",
13
- parentId: "ROOT",
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: "graphql",
22
- kind: "graphql",
23
- parentId: "application",
21
+ id: 'graphql',
22
+ kind: 'graphql',
23
+ parentId: 'application',
24
24
  settings: {
25
- title: "",
26
- description: "",
27
- graphqlEndpoint: "/test-graphql",
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("/test-graphql");
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
  });
@@ -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("unit", () => {
6
+ test('unit', () => {
7
7
  const graphqlResource = new resource_2.GraphqlResource({
8
- id: "test-graphql",
9
- kind: "graphql",
10
- parentId: "test-application",
8
+ id: 'test-graphql',
9
+ kind: 'graphql',
10
+ parentId: 'test-application',
11
11
  settings: {
12
- title: "",
13
- description: "",
14
- graphqlEndpoint: "/test-graphql",
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: "Post",
23
+ name: 'Post',
24
24
  fields: {
25
- id: "Int!",
26
- title: "String",
27
- votes: "Int",
28
- authorId: "Int",
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: "[Post]",
33
+ type: '[Post]',
34
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
- },
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: "test-a",
47
- kind: "a",
48
- parentId: "test-application",
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();
@@ -1,6 +1,6 @@
1
- import { HandlerSpecificResourceSettings } from "@ldsg/handler";
2
- import { ResourceDefinitionSpecificResourceSettings } from "@ldsg/resource-definition";
3
- import { GeneralResourceSettings } from "@ldsg/types";
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
  * 实例化资源处理程序普通资源配置
@@ -1 +1 @@
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;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAIlE,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAQnE,CAAC;AAEJ,eAAO,MAAM,6CAA6C,EAAE,uBACjB,CAAC;AAE5C,eAAO,MAAM,8CAA8C,EAAE,0CAI1D,CAAC;AAEJ,eAAO,MAAM,wBAAwB,aAAa,CAAC"}
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,+BAOrE,CAAC;AAEF,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAE5D,CAAC;AAEF,eAAO,MAAM,wBAAwB,aAAa,CAAC"}
package/dist/constants.js CHANGED
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_GRAPHQL_ENDPOINT = exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
4
- const application_1 = require("@ldsg/application");
5
4
  /**
6
5
  * Instantiate Resource Handler General Resource Settings
7
6
  * 实例化资源处理程序普通资源配置
8
7
  */
9
8
  exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = {
10
- title: "GraphQL实例化资源处理程序",
11
- description: "",
9
+ title: 'GraphQL实例化资源处理程序',
10
+ description: ''
12
11
  };
13
12
  /**
14
13
  * Instantiate Resource Handler Specific Resource Settings
@@ -19,13 +18,15 @@ exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = {
19
18
  code: `export * from "@ldsg/graphql";`,
20
19
  dependencies: [
21
20
  {
22
- name: "@ldsg/graphql",
23
- },
24
- ],
21
+ name: '@ldsg/graphql'
22
+ }
23
+ ]
24
+ };
25
+ exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
26
+ title: 'GraphQL资源定义',
27
+ description: ''
25
28
  };
26
- exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = { title: "GraphQL资源定义", description: "" };
27
29
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
28
- kind: "graphql",
29
- parentKind: application_1.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS.kind,
30
+ kind: 'graphql'
30
31
  };
31
- exports.DEFAULT_GRAPHQL_ENDPOINT = "/graphql";
32
+ exports.DEFAULT_GRAPHQL_ENDPOINT = '/graphql';
package/dist/handler.d.ts CHANGED
@@ -1,8 +1,6 @@
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
- export declare const handler: Handler<[
6
- InstantiateResourceParams<HandlerExtendedResourceSettings<GraphqlSpecificResourceSettings>>
7
- ], InstantiateResourceRes<GraphqlResource>>;
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
+ export declare const handler: Handler<InstantiateResourceParams<HandlerExtendedResourceSettings<GraphqlSpecificResourceSettings>>, InstantiateResourceRes<GraphqlResource>>;
8
6
  //# sourceMappingURL=handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1D,eAAO,MAAM,OAAO,EAAE,OAAO,CAC3B;IACE,yBAAyB,CACvB,+BAA+B,CAAC,+BAA+B,CAAC,CACjE;CACF,EACD,sBAAsB,CAAC,eAAe,CAAC,CAClB,CAAC"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1D,eAAO,MAAM,OAAO,EAAE,OAAO,CAC3B,yBAAyB,CAAC,+BAA+B,CAAC,+BAA+B,CAAC,CAAC,EAC3F,sBAAsB,CAAC,eAAe,CAAC,CAClB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./constants";
2
- export * from "./handler";
3
- export * from "./instantiate-resource";
4
- export * from "./resource";
5
- export * from "./types";
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 "@ldsg/handler";
2
- import { InstantiateResource } from "@ldsg/resource";
3
- import { GraphqlResource } from "./resource";
4
- import { GraphqlSpecificResourceSettings } from "./types";
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
@@ -6,7 +6,7 @@ const instantiateResource = (params) => {
6
6
  const { resourceConstructorParams } = params;
7
7
  const resource = new resource_1.GraphqlResource(resourceConstructorParams);
8
8
  const res = {
9
- resource,
9
+ resource
10
10
  };
11
11
  return res;
12
12
  };
@@ -1,6 +1,6 @@
1
- import { ExtendExpressApp } from "@ldsg/application";
2
- import { Resource } from "@ldsg/resource";
3
- import { GraphqlSpecificResourceSettings } from "./types";
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: () => {
@@ -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;AAK1C,OAAO,EAGL,+BAA+B,EAEhC,MAAM,SAAS,CAAC;AAEjB,qBAAa,eAAgB,SAAQ,QAAQ,CAAC,+BAA+B,CAAC;IAC5E,gBAAgB,EAAE,gBAAgB,CAehC;IAEF,gBAAgB;;MA+Dd;CACH"}
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;AAM1C,OAAO,EAGL,+BAA+B,EAEhC,MAAM,SAAS,CAAC;AAEjB,qBAAa,eAAgB,SAAQ,QAAQ,CAAC,+BAA+B,CAAC;IAC5E,gBAAgB,EAAE,gBAAgB,CAiBhC;IAEF,gBAAgB;;MA0Dd;CACH"}
package/dist/resource.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GraphqlResource = void 0;
4
4
  const resource_1 = require("@ldsg/resource");
5
+ const graphql_1 = require("graphql");
5
6
  const graphql_compose_1 = require("graphql-compose");
6
7
  const graphql_middleware_1 = require("graphql-middleware");
7
8
  const graphql_yoga_1 = require("graphql-yoga");
@@ -11,11 +12,12 @@ class GraphqlResource extends resource_1.Resource {
11
12
  super(...arguments);
12
13
  this.extendExpressApp = async (params) => {
13
14
  const { app } = params;
14
- const { settings: { graphqlEndpoint = constants_1.DEFAULT_GRAPHQL_ENDPOINT }, } = this;
15
+ const { settings: { graphqlEndpoint = constants_1.DEFAULT_GRAPHQL_ENDPOINT } } = this;
15
16
  const { schema } = this.getGraphQLSchema();
17
+ const lexicographicSortSchemaRes = (0, graphql_1.lexicographicSortSchema)(schema);
16
18
  const yoga = (0, graphql_yoga_1.createYoga)({
17
19
  graphqlEndpoint,
18
- schema,
20
+ schema: lexicographicSortSchemaRes
19
21
  });
20
22
  app.use(yoga.graphqlEndpoint, yoga);
21
23
  };
@@ -26,21 +28,21 @@ class GraphqlResource extends resource_1.Resource {
26
28
  /**
27
29
  * 同级资源
28
30
  */
29
- resources: peerResources, } = getFilteredResources({
30
- parentId,
31
+ resources: peerResources } = getFilteredResources({
32
+ parentId
31
33
  });
32
34
  peerResources.forEach((resource) => {
33
35
  var _a;
34
36
  (_a = resource.modifyGraphQLSchema) === null || _a === void 0 ? void 0 : _a.call(resource, {
35
- schemaComposer,
37
+ schemaComposer
36
38
  });
37
39
  });
38
40
  const {
39
41
  /**
40
42
  * 子级资源
41
43
  */
42
- resources: childResources, } = getFilteredResources({
43
- parentId: id,
44
+ resources: childResources } = getFilteredResources({
45
+ parentId: id
44
46
  });
45
47
  const graphqlMiddlewareInfos = [];
46
48
  childResources.forEach((resource) => {
@@ -55,7 +57,7 @@ class GraphqlResource extends resource_1.Resource {
55
57
  const sortedGraphqlMiddlewares = sortedGraphqlMiddlewareInfos.map((sortedGraphqlMiddlewareInfo) => sortedGraphqlMiddlewareInfo.middleware);
56
58
  const schemaWithMiddleware = (0, graphql_middleware_1.applyMiddleware)(schema, ...sortedGraphqlMiddlewares);
57
59
  const res = {
58
- schema: schemaWithMiddleware,
60
+ schema: schemaWithMiddleware
59
61
  };
60
62
  return res;
61
63
  };
@@ -1,4 +1,4 @@
1
- import { IMiddleware, IMiddlewareGenerator } from "graphql-middleware";
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;
@@ -1,5 +1,5 @@
1
- export * from "./graphql-middleware-info";
2
- export * from "./modify-graphql-schema";
3
- export * from "./schema-composer-params";
4
- export * from "./specific-resource-settings";
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
@@ -1,3 +1,3 @@
1
- import { SchemaComposerParams } from "./schema-composer-params";
1
+ import { SchemaComposerParams } from './schema-composer-params';
2
2
  export type ModifyGraphQLSchema = (params: SchemaComposerParams) => void;
3
3
  //# sourceMappingURL=modify-graphql-schema.d.ts.map
@@ -1,4 +1,4 @@
1
- import { SchemaComposer } from "graphql-compose";
1
+ import { SchemaComposer } from 'graphql-compose';
2
2
  export interface SchemaComposerParams {
3
3
  schemaComposer: SchemaComposer;
4
4
  }
@@ -1,4 +1,4 @@
1
- import { SpecificResourceSettings } from "@ldsg/types";
1
+ import { SpecificResourceSettings } from '@ldsg/types';
2
2
  export interface GraphqlSpecificResourceSettings extends SpecificResourceSettings {
3
3
  /**
4
4
  * GraphQL Endpoint
@@ -1 +1 @@
1
- {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,WAAW,+BACf,SAAQ,wBAAwB;IAChC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
1
+ {"version":3,"file":"specific-resource-settings.d.ts","sourceRoot":"","sources":["../../src/types/specific-resource-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,WAAW,+BAAgC,SAAQ,wBAAwB;IAC/E;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,31 +1,37 @@
1
1
  {
2
2
  "name": "@ldsg/graphql",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "description": "",
5
+ "keywords": [],
6
+ "license": "MIT",
7
+ "author": "wanxger",
5
8
  "main": "dist/index.js",
9
+ "types": "dist",
6
10
  "files": [
7
11
  "dist/"
8
12
  ],
9
- "types": "dist",
10
- "keywords": [],
11
- "author": "wanxger",
12
- "license": "MIT",
13
- "publishConfig": {
14
- "access": "public"
15
- },
16
13
  "dependencies": {
14
+ "graphql": "16.11.0",
17
15
  "graphql-compose": "^9.1.0",
16
+ "graphql-middleware": "^6.1.35",
18
17
  "graphql-yoga": "^5.13.4",
19
- "@ldsg/handler": "0.3.9",
20
- "@ldsg/resource": "0.3.9",
21
- "@ldsg/resource-definition": "0.3.9"
18
+ "@ldsg/handler": "0.3.10",
19
+ "@ldsg/resource-definition": "0.3.10",
20
+ "@ldsg/resource": "0.3.10"
22
21
  },
23
22
  "devDependencies": {
23
+ "@types/jest": "^29.5.2",
24
24
  "@types/supertest": "^6.0.0",
25
- "graphql": "16.11.0",
25
+ "jest": "^29.5.0",
26
26
  "supertest": "^6.3.4",
27
- "@ldsg/application": "0.3.9",
28
- "@ldsg/types": "0.3.9"
27
+ "ts-jest": "^29.1.5",
28
+ "ts-node": "^10.9.2",
29
+ "typescript": "^5.8.3",
30
+ "@ldsg/application": "0.3.10",
31
+ "@ldsg/types": "0.3.10"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
29
35
  },
30
36
  "scripts": {
31
37
  "build": "tsc --project tsconfig.build.json",