@vocollege/app 0.0.134 → 0.0.135

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,6 +6,7 @@ declare class GraphClient {
6
6
  errorLink: ApolloLink;
7
7
  authLink: ApolloLink;
8
8
  omitTypenameLink: ApolloLink;
9
+ transformVariablesLink: ApolloLink;
9
10
  };
10
11
  }
11
12
  export default GraphClient;
@@ -137,12 +137,28 @@ var GraphClient = /** @class */ (function () {
137
137
  // "field",
138
138
  // ],
139
139
  // },
140
+ ValidigGeneralSurveyRow: {
141
+ fields: {
142
+ options: {
143
+ read: function (existing) {
144
+ return existing ? JSON.parse(existing) : existing;
145
+ },
146
+ // merge(existing = "", incoming: "") {
147
+ // console.log("existing", existing);
148
+ // console.log("incoming", incoming);
149
+ // // return [...existing, ...incoming];
150
+ // return incoming;
151
+ // },
152
+ },
153
+ },
154
+ },
140
155
  },
141
156
  }),
142
157
  link: (0, client_1.from)([
143
158
  links.errorLink,
144
159
  links.authLink,
145
160
  links.omitTypenameLink,
161
+ links.transformVariablesLink,
146
162
  httpLink,
147
163
  ]),
148
164
  });
@@ -218,10 +234,46 @@ var GraphClient = /** @class */ (function () {
218
234
  }
219
235
  return forward(operation);
220
236
  });
237
+ var transformVariablesLink = new client_1.ApolloLink(function (operation, forward) {
238
+ var operationName = operation.operationName, variables = operation.variables;
239
+ switch (operationName) {
240
+ // Manipulate fields on GeneralSurvey.
241
+ case "CreateGeneralSurvey":
242
+ case "UpdateGeneralSurvey":
243
+ Object.keys(variables.input)
244
+ .filter(function (key) { return Array.isArray(variables.input[key]); })
245
+ .map(function (key) {
246
+ // JSON stringify GeneralSurveyRow.options.
247
+ variables.input[key]
248
+ .filter(function (v) { return v === null || v === void 0 ? void 0 : v.options; })
249
+ .map(function (v) {
250
+ if (v.options) {
251
+ v.options = JSON.stringify(v.options);
252
+ }
253
+ });
254
+ });
255
+ break;
256
+ }
257
+ // Traverse the variables and convert objects to JSON strings as needed
258
+ // const transformVariables = (vars) => {
259
+ // if (!vars || typeof vars !== 'object') return vars;
260
+ // return Object.keys(vars).reduce((acc, key) => {
261
+ // const value = vars[key];
262
+ // // Check if the value is an object that needs conversion
263
+ // acc[key] = value && typeof value === 'object' && !(value instanceof Array)
264
+ // ? JSON.stringify(value)
265
+ // : value;
266
+ // return acc;
267
+ // }, {});
268
+ // };
269
+ // operation.variables = transformVariables(variables);
270
+ return forward(operation);
271
+ });
221
272
  return {
222
273
  errorLink: errorLink,
223
274
  authLink: authLink,
224
275
  omitTypenameLink: omitTypenameLink,
276
+ transformVariablesLink: transformVariablesLink,
225
277
  };
226
278
  };
227
279
  return GraphClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocollege/app",
3
- "version": "0.0.134",
3
+ "version": "0.0.135",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -39,7 +39,7 @@
39
39
  "graphql": "^14.0.0 || ^15.0.0",
40
40
  "he": "^1.2.0",
41
41
  "js-cookie": "^3.0.1",
42
- "react": "^18.1.0",
42
+ "react": "^18.3.1",
43
43
  "react-toastify": "^8.0.0"
44
44
  }
45
45
  }
@@ -91,12 +91,30 @@ class GraphClient {
91
91
  // "field",
92
92
  // ],
93
93
  // },
94
+
95
+ ValidigGeneralSurveyRow: {
96
+ fields: {
97
+ options: {
98
+ read(existing) {
99
+ return existing ? JSON.parse(existing) : existing;
100
+ },
101
+ // merge(existing = "", incoming: "") {
102
+ // console.log("existing", existing);
103
+ // console.log("incoming", incoming);
104
+
105
+ // // return [...existing, ...incoming];
106
+ // return incoming;
107
+ // },
108
+ },
109
+ },
110
+ },
94
111
  },
95
112
  }),
96
113
  link: from([
97
114
  links.errorLink,
98
115
  links.authLink,
99
116
  links.omitTypenameLink,
117
+ links.transformVariablesLink,
100
118
  httpLink,
101
119
  ]),
102
120
  });
@@ -192,10 +210,54 @@ class GraphClient {
192
210
  return forward(operation);
193
211
  });
194
212
 
213
+ const transformVariablesLink = new ApolloLink((operation, forward) => {
214
+ const { operationName, variables } = operation;
215
+
216
+ switch (operationName) {
217
+ // Manipulate fields on GeneralSurvey.
218
+ case "CreateGeneralSurvey":
219
+ case "UpdateGeneralSurvey":
220
+ Object.keys(variables.input)
221
+ .filter((key: string) => Array.isArray(variables.input[key]))
222
+ .map((key: string) => {
223
+ // JSON stringify GeneralSurveyRow.options.
224
+ variables.input[key]
225
+ .filter((v: GeneralObject) => v?.options)
226
+ .map((v: GeneralObject) => {
227
+ if (v.options) {
228
+ v.options = JSON.stringify(v.options);
229
+ }
230
+ });
231
+ });
232
+ break;
233
+ }
234
+
235
+ // Traverse the variables and convert objects to JSON strings as needed
236
+ // const transformVariables = (vars) => {
237
+ // if (!vars || typeof vars !== 'object') return vars;
238
+
239
+ // return Object.keys(vars).reduce((acc, key) => {
240
+ // const value = vars[key];
241
+
242
+ // // Check if the value is an object that needs conversion
243
+ // acc[key] = value && typeof value === 'object' && !(value instanceof Array)
244
+ // ? JSON.stringify(value)
245
+ // : value;
246
+
247
+ // return acc;
248
+ // }, {});
249
+ // };
250
+
251
+ // operation.variables = transformVariables(variables);
252
+
253
+ return forward(operation);
254
+ });
255
+
195
256
  return {
196
257
  errorLink,
197
258
  authLink,
198
259
  omitTypenameLink,
260
+ transformVariablesLink,
199
261
  };
200
262
  }
201
263