@webresto/graphql 1.3.3 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -223,17 +223,12 @@ function createType(model) {
223
223
  scalarType = scalarTypes[relationModel.attributes[relationModel.primaryKey].type];
224
224
  const name = sails.models[attributes[prop].model.toLowerCase()].globalId;
225
225
  type += ` ${prop}: ${name}\n`;
226
- // todelete
227
- type += ` ${prop}Id: ${scalarType}\n`;
228
226
  }
229
227
  // COLLECTION SCHEMA GENERATION
230
228
  if (attributes[prop].collection) {
231
229
  scalarType = scalarTypes[attributes[sails.models[attributes[prop].collection.toLowerCase()].primaryKey].type.toLowerCase()];
232
230
  const name = sails.models[attributes[prop].collection.toLowerCase()].globalId;
233
- console.log(1, scalarType);
234
231
  type += ` ${prop}: [${name}]\n`;
235
- // todelete
236
- type += ` ${prop}Ids: ${scalarType}\n`;
237
232
  }
238
233
  }
239
234
  if (customFields[modelName]) {
@@ -228,20 +228,13 @@ function createType(model) {
228
228
  scalarType = scalarTypes[relationModel.attributes[relationModel.primaryKey].type]
229
229
  const name = sails.models[attributes[prop].model.toLowerCase()].globalId;
230
230
  type += ` ${prop}: ${name}\n`;
231
-
232
- // todelete
233
- type += ` ${prop}Id: ${scalarType}\n`;
234
231
  }
235
232
 
236
233
  // COLLECTION SCHEMA GENERATION
237
234
  if (attributes[prop].collection) {
238
235
  scalarType = scalarTypes[attributes[sails.models[attributes[prop].collection.toLowerCase()].primaryKey].type.toLowerCase()]
239
236
  const name = sails.models[attributes[prop].collection.toLowerCase()].globalId;
240
- console.log(1,scalarType)
241
237
  type += ` ${prop}: [${name}]\n`;
242
-
243
- // todelete
244
- type += ` ${prop}Ids: ${scalarType}\n`;
245
238
  }
246
239
  }
247
240
  if (customFields[modelName]) {
package/package.json CHANGED
@@ -60,5 +60,5 @@
60
60
  "test:js": "mocha test/bootstrap.js './test/{,!(fixture)/**}/*.test.js' --exit",
61
61
  "test:init": "cd ./test/fixture && npm i --no-package-lock --prefix ./ && cd -"
62
62
  },
63
- "version": "1.3.3"
63
+ "version": "1.3.6"
64
64
  }
@@ -16,4 +16,10 @@ export declare const additionalResolver: {
16
16
  Group: {
17
17
  parentGroup: (parent: any, args: any, context: any, info: any) => Promise<any>;
18
18
  };
19
+ Order: {
20
+ dishes: (parent: any, args: any, context: any, info: any) => Promise<any>;
21
+ };
22
+ OrderDish: {
23
+ dish: (parent: any, args: any, context: any, info: any) => Promise<any>;
24
+ };
19
25
  };
@@ -70,7 +70,7 @@ exports.additionalResolver = {
70
70
  });
71
71
  dataloaders.set(info.fieldNodes, dl);
72
72
  }
73
- return dl.load(parent.parentGroup);
73
+ return await dl.load(parent.parentGroup);
74
74
  },
75
75
  images: async (parent, args, context, info) => {
76
76
  if (!parent.id)
@@ -87,7 +87,7 @@ exports.additionalResolver = {
87
87
  });
88
88
  dataloaders.set(info.fieldNodes, dl);
89
89
  }
90
- return dl.load(parent.id);
90
+ return await dl.load(parent.id);
91
91
  }
92
92
  },
93
93
  Group: {
@@ -108,7 +108,35 @@ exports.additionalResolver = {
108
108
  });
109
109
  dataloaders.set(info.fieldNodes, dl);
110
110
  }
111
- return dl.load(parent.parentGroup);
111
+ return await dl.load(parent.parentGroup);
112
112
  }
113
- }
113
+ },
114
+ Order: {
115
+ dishes: async (parent, args, context, info) => {
116
+ if (typeof parent.dishes === "object") {
117
+ return parent.dishes;
118
+ }
119
+ return await OrderDish.find({ order: parent.id });
120
+ },
121
+ },
122
+ OrderDish: {
123
+ dish: async (parent, args, context, info) => {
124
+ if (!parent.dish)
125
+ return;
126
+ if (!context.dataloaders)
127
+ context.dataloaders = new WeakMap();
128
+ const dataloaders = context.dataloaders;
129
+ if (typeof parent.dish === "object") {
130
+ return parent.dish;
131
+ }
132
+ let dl = dataloaders.get(info.fieldNodes);
133
+ if (!dl) {
134
+ dl = new DataLoader(async (dishId) => {
135
+ return await Dish.find({ id: dishId }).sort('id ASC');
136
+ });
137
+ dataloaders.set(info.fieldNodes, dl);
138
+ }
139
+ return await dl.load(parent.dish);
140
+ },
141
+ },
114
142
  };
@@ -68,7 +68,7 @@ export const additionalResolver = {
68
68
  });
69
69
  dataloaders.set(info.fieldNodes, dl);
70
70
  }
71
- return dl.load(parent.parentGroup);
71
+ return await dl.load(parent.parentGroup);
72
72
  },
73
73
  images: async (parent, args, context, info) => {
74
74
  if (!parent.id) return;
@@ -84,7 +84,7 @@ export const additionalResolver = {
84
84
  });
85
85
  dataloaders.set(info.fieldNodes, dl);
86
86
  }
87
- return dl.load(parent.id);
87
+ return await dl.load(parent.id);
88
88
  }
89
89
  },
90
90
  Group: {
@@ -105,7 +105,40 @@ export const additionalResolver = {
105
105
  });
106
106
  dataloaders.set(info.fieldNodes, dl);
107
107
  }
108
- return dl.load(parent.parentGroup);
108
+ return await dl.load(parent.parentGroup);
109
109
  }
110
- }
110
+ },
111
+ Order: {
112
+ dishes: async (parent, args, context, info) => {
113
+ if (typeof parent.dishes === "object") {
114
+ return parent.dishes;
115
+ }
116
+
117
+ return await OrderDish.find({order: parent.id});
118
+
119
+ },
120
+
121
+ },
122
+ OrderDish: {
123
+ dish: async (parent, args, context, info) => {
124
+
125
+ if (!parent.dish) return;
126
+ if (!context.dataloaders) context.dataloaders = new WeakMap();
127
+ const dataloaders = context.dataloaders;
128
+
129
+ if (typeof parent.dish === "object") {
130
+ return parent.dish;
131
+ }
132
+
133
+ let dl = dataloaders.get(info.fieldNodes);
134
+ if (!dl) {
135
+ dl = new DataLoader(async (dishId: string) => {
136
+ return await Dish.find({id: dishId}).sort('id ASC');
137
+ });
138
+ dataloaders.set(info.fieldNodes, dl);
139
+ }
140
+ return await dl.load(parent.dish);
141
+ },
142
+
143
+ },
111
144
  }
package/src/graphql.js CHANGED
@@ -65,11 +65,6 @@ exports.default = {
65
65
  type: String
66
66
  message: String
67
67
  }
68
- type Street {
69
- id: String
70
- name: String
71
- customData: Json
72
- }
73
68
  type Action {
74
69
  type: String
75
70
  data: Json
package/src/graphql.ts CHANGED
@@ -74,11 +74,6 @@ export default {
74
74
  type: String
75
75
  message: String
76
76
  }
77
- type Street {
78
- id: String
79
- name: String
80
- customData: Json
81
- }
82
77
  type Action {
83
78
  type: String
84
79
  data: Json
@@ -141,6 +136,7 @@ export default {
141
136
  getEmitter().on("core-maintenance-disabled", "graphql", function () {
142
137
  pubsub.publish("maintenance", null);
143
138
  });
139
+
144
140
  let apolloServer
145
141
  try {
146
142
  apolloServer = new ApolloServer({
@@ -3,8 +3,8 @@ declare const _default: {
3
3
  checkOrder: {
4
4
  def: string;
5
5
  fn: (parent: any, args: any, context: any) => Promise<void | {
6
+ message: any;
6
7
  order: import("@webresto/core/models/Order").default;
7
- message?: undefined;
8
8
  } | {
9
9
  message: {
10
10
  type: string;
@@ -62,11 +62,10 @@ exports.default = {
62
62
  order.customData.callback = data.customData.callback;
63
63
  }
64
64
  await Order.update({ id: order.id }, order).fetch();
65
- let success;
66
- success = await Order.check(order.id, data.customer, isSelfService, data.address, data.paymentMethodId);
67
- order = await Order.findOne(data.orderId).populateAll();
65
+ await Order.check(order.id, data.customer, isSelfService, data.address, data.paymentMethodId);
66
+ order = await Order.findOne(data.orderId);
68
67
  let message;
69
- if (success && order.state === "CHECKOUT") {
68
+ if (order.state === "CHECKOUT") {
70
69
  message = {
71
70
  type: "info",
72
71
  title: "Внимание",
@@ -77,16 +76,17 @@ exports.default = {
77
76
  }
78
77
  else {
79
78
  if (order.message) {
80
- return eventHelper.sendMessage(args.orderId, {
79
+ message = {
81
80
  type: "error",
82
81
  title: "Внимание",
83
82
  message: order.message
84
83
  ? order.message
85
84
  : "Не удалось проверить заказ.",
86
- });
85
+ };
87
86
  }
88
87
  }
89
- return { order: order };
88
+ eventHelper.sendMessage(args.orderId, message);
89
+ return { message: message, order: order };
90
90
  }
91
91
  catch (e) {
92
92
  let message = {
@@ -203,6 +203,7 @@ exports.default = {
203
203
  // }
204
204
  // }
205
205
  await Order.order(order.id);
206
+ order = await Order.findOne({ id: data.orderId });
206
207
  const message = {
207
208
  type: "info",
208
209
  title: "Успешно",
@@ -42,6 +42,7 @@ export default {
42
42
  message: "Корзина уже заказана",
43
43
  });
44
44
  }
45
+
45
46
  if (data.paymentMethodId) {
46
47
  if (!PaymentMethod.checkAvailable(data.paymentMethodId)) {
47
48
  return eventHelper.sendMessage(args.orderId, {
@@ -70,19 +71,19 @@ export default {
70
71
 
71
72
  await Order.update({ id: order.id }, order).fetch();
72
73
 
73
- let success: boolean;
74
-
75
- success = await Order.check(
74
+ await Order.check(
76
75
  order.id,
77
76
  data.customer,
78
77
  isSelfService,
79
78
  data.address,
80
79
  data.paymentMethodId
81
80
  );
82
- order = await Order.findOne(data.orderId).populateAll();
81
+
82
+ order = await Order.findOne(data.orderId);
83
+
83
84
  let message;
84
85
 
85
- if (success && order.state === "CHECKOUT") {
86
+ if (order.state === "CHECKOUT") {
86
87
  message = {
87
88
  type: "info",
88
89
  title: "Внимание",
@@ -93,17 +94,19 @@ export default {
93
94
 
94
95
  } else {
95
96
  if (order.message) {
96
- return eventHelper.sendMessage(args.orderId, {
97
+ message = {
97
98
  type: "error",
98
99
  title: "Внимание",
99
100
  message: order.message
100
101
  ? order.message
101
102
  : "Не удалось проверить заказ.",
102
- });
103
+ }
103
104
  }
104
105
  }
105
106
 
106
- return { order: order };
107
+ eventHelper.sendMessage(args.orderId, message);
108
+
109
+ return { message: message, order: order };
107
110
  } catch (e) {
108
111
  let message = {
109
112
  type: "error",
@@ -219,7 +222,7 @@ export default {
219
222
  // }
220
223
 
221
224
  await Order.order(order.id);
222
-
225
+ order = await Order.findOne({ id: data.orderId })
223
226
  const message = {
224
227
  type: "info",
225
228
  title: "Успешно",
@@ -27,7 +27,7 @@
27
27
  process.chdir(__dirname);
28
28
 
29
29
  process.env.DEV = "TRUE";
30
-
30
+ process.env.PORT = 42776;
31
31
 
32
32
  // Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files).
33
33
  var sails;
@@ -2,7 +2,6 @@ const expect = require("chai").expect;
2
2
  describe('GraphQl', function () {
3
3
  it('Added fields exist in schema', async () => {
4
4
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
5
- console.log(graphql);
6
5
  const result = await graphql.getServer().executeOperation({
7
6
  query: '{dish { id } \n group { id }}'
8
7
  });
@@ -4,7 +4,6 @@ describe('GraphQl', function () {
4
4
  it('Added fields exist in schema', async () => {
5
5
 
6
6
  const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
7
- console.log(graphql)
8
7
  const result = await graphql.getServer().executeOperation({
9
8
  query: '{dish { id } \n group { id }}'
10
9
  });
@@ -0,0 +1,82 @@
1
+ const expect = require("chai").expect;
2
+ describe('Send order to restarant', function () {
3
+ it('Create new', async () => {
4
+ const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
5
+ const result = await graphql.getServer().executeOperation({
6
+ query: `
7
+ {order(orderId:"test-cart"){
8
+ id
9
+ total
10
+ }}`
11
+ });
12
+ expect(result.errors).to.be.undefined;
13
+ });
14
+ it('orderAddDish', async () => {
15
+ const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
16
+ const result = await graphql.getServer().executeOperation({
17
+ query: `
18
+ mutation{orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-cart", amount: 1){
19
+ dishes {
20
+ dish {
21
+ id
22
+ name
23
+ price
24
+ }
25
+ itemTotal
26
+ }
27
+ total
28
+ }}
29
+ `
30
+ });
31
+ expect(result.data.orderAddDish.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
32
+ });
33
+ it('checkOrder', async () => {
34
+ const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
35
+ const result = await graphql.getServer().executeOperation({
36
+ query: `
37
+ mutation{checkOrder(orderId:"test-cart", paymentMethodId: "", address: {city: "town", street: "test", home: "123"}, customer: {phone: {code: "+1", number: "0000000000"}, name: "Piter Parker"}) {
38
+ order {
39
+ id
40
+ state
41
+ dishes{
42
+ dish {
43
+ name
44
+ id
45
+ }
46
+ }
47
+ }
48
+ message {
49
+ title
50
+ message
51
+ }
52
+ }}
53
+ `
54
+ });
55
+ expect(result.data.checkOrder.order.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
56
+ });
57
+ it('sendOrder', async () => {
58
+ const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
59
+ const result = await graphql.getServer().executeOperation({
60
+ query: `
61
+ mutation{sendOrder(orderId:"test-cart") {
62
+ order {
63
+ id
64
+ state
65
+ dishes{
66
+ dish {
67
+ name
68
+ id
69
+ }
70
+ amount
71
+ }
72
+ }
73
+ message {
74
+ title
75
+ message
76
+ }
77
+ }}
78
+ `
79
+ });
80
+ expect(result.data.sendOrder.order.state).to.equal("ORDER");
81
+ });
82
+ });
@@ -0,0 +1,107 @@
1
+ const expect = require("chai").expect;
2
+
3
+ describe('Send order to restarant', function () {
4
+ it('Create new', async () => {
5
+
6
+ const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
7
+ const result = await graphql.getServer().executeOperation({
8
+ query: `
9
+ {order(orderId:"test-cart"){
10
+ id
11
+ total
12
+ }}`
13
+ });
14
+
15
+ expect(result.errors).to.be.undefined;
16
+ });
17
+
18
+
19
+
20
+
21
+ it('orderAddDish', async () => {
22
+
23
+ const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
24
+
25
+ const result = await graphql.getServer().executeOperation({
26
+ query: `
27
+ mutation{orderAddDish(dishId: "df19cbbc-c026-595e-9296-1c8a378da6b3", orderId:"test-cart", amount: 1){
28
+ dishes {
29
+ dish {
30
+ id
31
+ name
32
+ price
33
+ }
34
+ itemTotal
35
+ }
36
+ total
37
+ }}
38
+ `
39
+ });
40
+ expect(result.data.orderAddDish.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
41
+ });
42
+
43
+
44
+ it('checkOrder', async () => {
45
+
46
+ const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
47
+
48
+ const result = await graphql.getServer().executeOperation({
49
+ query: `
50
+ mutation{checkOrder(orderId:"test-cart", paymentMethodId: "", address: {city: "town", street: "test", home: "123"}, customer: {phone: {code: "+1", number: "0000000000"}, name: "Piter Parker"}) {
51
+ order {
52
+ id
53
+ state
54
+ dishes{
55
+ dish {
56
+ name
57
+ id
58
+ }
59
+ }
60
+ }
61
+ message {
62
+ title
63
+ message
64
+ }
65
+ }}
66
+ `
67
+ });
68
+ expect(result.data.checkOrder.order.dishes[0].dish.id).to.equal("df19cbbc-c026-595e-9296-1c8a378da6b3");
69
+ });
70
+
71
+
72
+
73
+ it('sendOrder', async () => {
74
+
75
+ const graphql = require('./../fixture/node_modules/@webresto/graphql/src/graphql').default;
76
+
77
+ const result = await graphql.getServer().executeOperation({
78
+ query: `
79
+ mutation{sendOrder(orderId:"test-cart") {
80
+ order {
81
+ id
82
+ state
83
+ dishes{
84
+ dish {
85
+ name
86
+ id
87
+ }
88
+ amount
89
+ }
90
+ }
91
+ message {
92
+ title
93
+ message
94
+ }
95
+ }}
96
+ `
97
+ });
98
+
99
+ expect(result.data.sendOrder.order.state).to.equal("ORDER");
100
+ });
101
+
102
+
103
+
104
+
105
+ });
106
+
107
+
package/todo.md CHANGED
@@ -1 +1 @@
1
- 1. Add support for multi websoketServer (several tests placed in lib dirrectory)
1
+ 1. Add support for multi websoketServer (several tests placed in lib dirrectory)
package/restApi.http DELETED
@@ -1,11 +0,0 @@
1
- @host = http://127.0.0.1:42777
2
-
3
- @host2 = https://api.lifenadym.webresto.dev
4
-
5
- GET {{host}}/api/0.5/menu
6
-
7
- ###
8
- GET {{host2}}/api/0.5/api/getNomenclature
9
-
10
- ###
11
- GET {{host}}/api/0.5/menu?groupSlug=sousy