@ctil/gql 1.1.2 → 1.1.4
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/index.cjs +9 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -245,8 +245,8 @@ declare function buildGraphQLQueryAggregate(input: QueryAggregateInput): {
|
|
|
245
245
|
interface MutationInput {
|
|
246
246
|
operationName: string;
|
|
247
247
|
fields: FieldInput[];
|
|
248
|
-
datas?: Record<string, any>[];
|
|
249
|
-
_set?: Record<string, any>[];
|
|
248
|
+
datas?: Record<string, any> | Record<string, any>[];
|
|
249
|
+
_set?: Record<string, any> | Record<string, any>[];
|
|
250
250
|
where?: WhereInput;
|
|
251
251
|
variables?: Record<string, any>;
|
|
252
252
|
variableName?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -245,8 +245,8 @@ declare function buildGraphQLQueryAggregate(input: QueryAggregateInput): {
|
|
|
245
245
|
interface MutationInput {
|
|
246
246
|
operationName: string;
|
|
247
247
|
fields: FieldInput[];
|
|
248
|
-
datas?: Record<string, any>[];
|
|
249
|
-
_set?: Record<string, any>[];
|
|
248
|
+
datas?: Record<string, any> | Record<string, any>[];
|
|
249
|
+
_set?: Record<string, any> | Record<string, any>[];
|
|
250
250
|
where?: WhereInput;
|
|
251
251
|
variables?: Record<string, any>;
|
|
252
252
|
variableName?: string;
|
package/dist/index.js
CHANGED
|
@@ -1154,21 +1154,17 @@ function buildGraphQLQueryAggregate(input) {
|
|
|
1154
1154
|
// src/builders/mutation.ts
|
|
1155
1155
|
function buildGraphQLMutation(input) {
|
|
1156
1156
|
const { operationName, fields, datas, _set, where, variables, variableName } = input;
|
|
1157
|
-
if (!operationName)
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1160
|
-
if (!fields || fields.length === 0) {
|
|
1161
|
-
throw new Error("fields is required");
|
|
1162
|
-
}
|
|
1157
|
+
if (!operationName) throw new Error("operationName is required");
|
|
1158
|
+
if (!fields || fields.length === 0) throw new Error("fields is required");
|
|
1163
1159
|
const finalVariables = { ...variables || {} };
|
|
1164
|
-
const varDefs = Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ");
|
|
1165
1160
|
const fieldsStr = buildFields(fields);
|
|
1161
|
+
const varDefs = Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ");
|
|
1166
1162
|
if (datas) {
|
|
1167
1163
|
const dataArray = Array.isArray(datas) ? datas : [datas];
|
|
1168
|
-
|
|
1169
|
-
|
|
1164
|
+
const datasArg = variables && variables.datas ? "$datas" : `[${dataArray.map((d) => `{ ${buildDataValue(d)} }`).join(" ")}]`;
|
|
1165
|
+
if (!variables || !variables.datas) finalVariables.datas = dataArray;
|
|
1170
1166
|
const query2 = `mutation ${operationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1171
|
-
${operationName}(${variableName
|
|
1167
|
+
${operationName}(${variableName ?? "datas"}: ${datasArg}) {
|
|
1172
1168
|
affected_rows
|
|
1173
1169
|
returning { ${fieldsStr} }
|
|
1174
1170
|
}
|
|
@@ -1176,11 +1172,9 @@ function buildGraphQLMutation(input) {
|
|
|
1176
1172
|
return { query: query2, variables: finalVariables };
|
|
1177
1173
|
}
|
|
1178
1174
|
if (_set) {
|
|
1179
|
-
if (!where)
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
finalVariables._set = _set;
|
|
1183
|
-
const setArg = "$_set";
|
|
1175
|
+
if (!where) throw new Error("update mutation requires where condition");
|
|
1176
|
+
const setArg = variables && variables._set ? "$_set" : Array.isArray(_set) ? `[${_set.map((s) => `{ ${buildDataValue(s)} }`).join(" ")}]` : `{ ${buildDataValue(_set)} }`;
|
|
1177
|
+
if (!variables || !variables._set) finalVariables._set = _set;
|
|
1184
1178
|
const whereArg = buildWhere(where);
|
|
1185
1179
|
const query2 = `mutation ${operationName}${varDefs ? `(${varDefs})` : ""} {
|
|
1186
1180
|
${operationName}(where: { ${whereArg} }, _set: ${setArg}) {
|