@ctil/gql 1.1.1 → 1.1.3
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 +10 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3989,22 +3989,18 @@ function buildGraphQLQueryAggregate(input) {
|
|
|
3989
3989
|
|
|
3990
3990
|
// src/builders/mutation.ts
|
|
3991
3991
|
function buildGraphQLMutation(input) {
|
|
3992
|
-
const { operationName, fields, datas, _set, where, variables } = input;
|
|
3993
|
-
if (!operationName)
|
|
3994
|
-
|
|
3995
|
-
}
|
|
3996
|
-
if (!fields || fields.length === 0) {
|
|
3997
|
-
throw new Error("fields is required");
|
|
3998
|
-
}
|
|
3992
|
+
const { operationName, fields, datas, _set, where, variables, variableName } = input;
|
|
3993
|
+
if (!operationName) throw new Error("operationName is required");
|
|
3994
|
+
if (!fields || fields.length === 0) throw new Error("fields is required");
|
|
3999
3995
|
const finalVariables = { ...variables || {} };
|
|
4000
|
-
const varDefs = Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ");
|
|
4001
3996
|
const fieldsStr = buildFields(fields);
|
|
3997
|
+
const varDefs = Object.keys(finalVariables).map((k) => `$${k}: String!`).join(", ");
|
|
4002
3998
|
if (datas) {
|
|
4003
3999
|
const dataArray = Array.isArray(datas) ? datas : [datas];
|
|
4004
|
-
|
|
4005
|
-
|
|
4000
|
+
const datasArg = variables && variables.datas ? "$datas" : `[${dataArray.map((d) => `{ ${buildDataValue(d)} }`).join(" ")}]`;
|
|
4001
|
+
if (!variables || !variables.datas) finalVariables.datas = dataArray;
|
|
4006
4002
|
const query2 = `mutation ${operationName}${varDefs ? `(${varDefs})` : ""} {
|
|
4007
|
-
${operationName}(${
|
|
4003
|
+
${operationName}(${variableName ?? "datas"}: ${datasArg}) {
|
|
4008
4004
|
affected_rows
|
|
4009
4005
|
returning { ${fieldsStr} }
|
|
4010
4006
|
}
|
|
@@ -4012,11 +4008,9 @@ function buildGraphQLMutation(input) {
|
|
|
4012
4008
|
return { query: query2, variables: finalVariables };
|
|
4013
4009
|
}
|
|
4014
4010
|
if (_set) {
|
|
4015
|
-
if (!where)
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
finalVariables._set = _set;
|
|
4019
|
-
const setArg = "$_set";
|
|
4011
|
+
if (!where) throw new Error("update mutation requires where condition");
|
|
4012
|
+
const setArg = variables && variables._set ? "$_set" : Array.isArray(_set) ? `[${_set.map((s) => `{ ${buildDataValue(s)} }`).join(" ")}]` : `{ ${buildDataValue(_set)} }`;
|
|
4013
|
+
if (!variables || !variables._set) finalVariables._set = _set;
|
|
4020
4014
|
const whereArg = buildWhere(where);
|
|
4021
4015
|
const query2 = `mutation ${operationName}${varDefs ? `(${varDefs})` : ""} {
|
|
4022
4016
|
${operationName}(where: { ${whereArg} }, _set: ${setArg}) {
|