@orion-js/graphql 3.0.33 → 3.0.40

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.
@@ -19,6 +19,9 @@ function getGraphQLType(type, options) {
19
19
  const graphQLType = getGraphQLType(type[0], options);
20
20
  return new graphql_1.GraphQLList(graphQLType);
21
21
  }
22
+ else if (typeof type === 'function' && type.getModel && type.__schemaId) {
23
+ return getGraphQLType(type.getModel(), options);
24
+ }
22
25
  else if (!type._isFieldType && ((0, isPlainObject_1.default)(type) || type.__isModel)) {
23
26
  const model = type.__isModel ? type : type.__model;
24
27
  if (!model || !model.__isModel)
@@ -10,8 +10,12 @@ const omit_1 = __importDefault(require("lodash/omit"));
10
10
  const getScalar_1 = __importDefault(require("../buildSchema/getType/getScalar"));
11
11
  const getStaticFields_1 = require("./getStaticFields");
12
12
  async function getParams(field) {
13
- const { type } = field;
14
- if ((0, isArray_1.default)(type)) {
13
+ let { type } = field;
14
+ if (typeof type === 'function' && type.getModel && type.__schemaId) {
15
+ const model = type.getModel();
16
+ return await getParams({ ...field, type: model });
17
+ }
18
+ else if ((0, isArray_1.default)(type)) {
15
19
  const serialized = await getParams({ ...field, type: type[0] });
16
20
  return {
17
21
  ...serialized,
@@ -1,26 +1,56 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const typed_model_1 = require("@orion-js/typed-model");
6
16
  const getField_1 = __importDefault(require("./getField"));
7
- it('should return a valid serialization of the field', async () => {
8
- const schema = {
9
- name: {
10
- type: String,
11
- a: '1234'
12
- }
13
- };
14
- const result = await (0, getField_1.default)(schema.name);
15
- expect(result).toEqual({ type: 'string', a: '1234', __graphQLType: 'String' });
16
- });
17
- it('should pass field options with simple array fields', async () => {
18
- const schema = {
19
- name: {
20
- type: [String],
21
- a: '1234'
22
- }
23
- };
24
- const result = await (0, getField_1.default)(schema.name);
25
- expect(result.a).toEqual(schema.name.a);
17
+ describe('Field serialization', () => {
18
+ it('should return a valid serialization of the field', async () => {
19
+ const schema = {
20
+ name: {
21
+ type: String,
22
+ a: '1234'
23
+ }
24
+ };
25
+ const result = await (0, getField_1.default)(schema.name);
26
+ expect(result).toEqual({ type: 'string', a: '1234', __graphQLType: 'String' });
27
+ });
28
+ it('should pass field options with simple array fields', async () => {
29
+ const schema = {
30
+ name: {
31
+ type: [String],
32
+ a: '1234'
33
+ }
34
+ };
35
+ const result = await (0, getField_1.default)(schema.name);
36
+ expect(result.a).toEqual(schema.name.a);
37
+ });
38
+ it('Should allow serialization of typed models', async () => {
39
+ let Point = class Point {
40
+ };
41
+ __decorate([
42
+ (0, typed_model_1.Prop)({ label: 'Name' }),
43
+ __metadata("design:type", String)
44
+ ], Point.prototype, "name", void 0);
45
+ Point = __decorate([
46
+ (0, typed_model_1.TypedModel)()
47
+ ], Point);
48
+ const schema = {
49
+ point: {
50
+ type: Point
51
+ }
52
+ };
53
+ const result = await (0, getField_1.default)(schema.point);
54
+ expect(result.type.name).toEqual({ type: 'string', label: 'Name', __graphQLType: 'String' });
55
+ });
26
56
  });
@@ -1 +1,2 @@
1
- export default function serializeSchema(params: any): Promise<any>;
1
+ import { Schema } from '@orion-js/schema';
2
+ export default function serializeSchema(params: any): Promise<Schema>;
@@ -7,6 +7,9 @@ const getField_1 = __importDefault(require("./getField"));
7
7
  async function serializeSchema(params) {
8
8
  if (!params)
9
9
  return;
10
+ if (typeof params === 'function' && params.getModel && params.__schemaId) {
11
+ params = params.getModel().getCleanSchema(); // typed model
12
+ }
10
13
  if (Object.keys(params).length === 0)
11
14
  return;
12
15
  const fields = {};
@@ -1,8 +1,18 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const typed_model_1 = require("@orion-js/typed-model");
6
16
  const serializeSchema_1 = __importDefault(require("./serializeSchema"));
7
17
  it('should create a JSON of the schema', async () => {
8
18
  const schema = {
@@ -17,9 +27,30 @@ it('should pass field options', async () => {
17
27
  const schema = {
18
28
  name: {
19
29
  type: [String],
20
- a: '1234'
30
+ label: '1234'
21
31
  }
22
32
  };
23
33
  const result = await (0, serializeSchema_1.default)(schema);
24
- expect(result.name.a).toEqual(schema.name.a);
34
+ expect(result.name).toEqual({
35
+ type: ['string'],
36
+ label: '1234',
37
+ __graphQLType: '[String]'
38
+ });
39
+ });
40
+ it('should serialize a typed model', async () => {
41
+ let Point = class Point {
42
+ };
43
+ __decorate([
44
+ (0, typed_model_1.Prop)({ label: 'Name' }),
45
+ __metadata("design:type", String)
46
+ ], Point.prototype, "name", void 0);
47
+ Point = __decorate([
48
+ (0, typed_model_1.TypedModel)()
49
+ ], Point);
50
+ const result = await (0, serializeSchema_1.default)(Point);
51
+ expect(result.name).toEqual({
52
+ type: 'string',
53
+ label: 'Name',
54
+ __graphQLType: 'String'
55
+ });
25
56
  });
@@ -18,6 +18,7 @@ const http_1 = require("@orion-js/http");
18
18
  const supertest_1 = __importDefault(require("supertest"));
19
19
  const typed_model_1 = require("@orion-js/typed-model");
20
20
  const cleanResolvers_1 = require("./cleanResolvers");
21
+ const models_1 = require("@orion-js/models");
21
22
  describe('Test GraphQL Server', () => {
22
23
  beforeEach(() => {
23
24
  (0, cleanResolvers_1.cleanResolvers)();
@@ -139,11 +140,23 @@ describe('Test GraphQL Server', () => {
139
140
  };
140
141
  };
141
142
  const user = (0, resolvers_1.resolver)({
142
- params: (0, typed_model_1.getModelForClass)(Params),
143
- returns: (0, typed_model_1.getModelForClass)(User),
143
+ params: Params,
144
+ returns: User,
144
145
  resolve
145
146
  });
146
- const resolvers = { user };
147
+ const model = (0, models_1.createModel)({
148
+ name: 'Model',
149
+ schema: {
150
+ user: { type: User }
151
+ }
152
+ });
153
+ const modelMutation = (0, resolvers_1.resolver)({
154
+ params: Params,
155
+ returns: [model],
156
+ mutation: true,
157
+ resolve
158
+ });
159
+ const resolvers = { user, modelMutation };
147
160
  const app = (0, http_1.express)();
148
161
  await (0, _1.startGraphQL)({
149
162
  resolvers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/graphql",
3
- "version": "3.0.33",
3
+ "version": "3.0.40",
4
4
  "main": "lib/index.js",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
@@ -13,12 +13,12 @@
13
13
  "upgrade-interactive": "yarn upgrade-interactive"
14
14
  },
15
15
  "dependencies": {
16
- "@orion-js/helpers": "^3.0.31",
17
- "@orion-js/http": "^3.0.32",
18
- "@orion-js/models": "^3.0.32",
19
- "@orion-js/resolvers": "^3.0.32",
20
- "@orion-js/schema": "^3.0.32",
21
- "@orion-js/typed-model": "^3.0.33",
16
+ "@orion-js/helpers": "^3.0.36",
17
+ "@orion-js/http": "^3.0.40",
18
+ "@orion-js/models": "^3.0.38",
19
+ "@orion-js/resolvers": "^3.0.37",
20
+ "@orion-js/schema": "^3.0.37",
21
+ "@orion-js/typed-model": "^3.0.38",
22
22
  "apollo-server-core": "3.5.0",
23
23
  "graphql-iso-date": "^3.6.1",
24
24
  "graphql-subscriptions": "^2.0.0",
@@ -43,5 +43,5 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
- "gitHead": "3ae1a9b2872f026dca2edb6684d87d66151bd71e"
46
+ "gitHead": "c0632276e6b8247bfe6ae2b2eee8815a3bcd441f"
47
47
  }