@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.d.cts CHANGED
@@ -249,6 +249,7 @@ interface MutationInput {
249
249
  _set?: Record<string, any>[];
250
250
  where?: WhereInput;
251
251
  variables?: Record<string, any>;
252
+ variableName?: string;
252
253
  }
253
254
  interface InsertOneInput {
254
255
  operationName: string;
package/dist/index.d.ts CHANGED
@@ -249,6 +249,7 @@ interface MutationInput {
249
249
  _set?: Record<string, any>[];
250
250
  where?: WhereInput;
251
251
  variables?: Record<string, any>;
252
+ variableName?: string;
252
253
  }
253
254
  interface InsertOneInput {
254
255
  operationName: string;
package/dist/index.js CHANGED
@@ -1153,22 +1153,18 @@ function buildGraphQLQueryAggregate(input) {
1153
1153
 
1154
1154
  // src/builders/mutation.ts
1155
1155
  function buildGraphQLMutation(input) {
1156
- const { operationName, fields, datas, _set, where, variables } = input;
1157
- if (!operationName) {
1158
- throw new Error("operationName is required");
1159
- }
1160
- if (!fields || fields.length === 0) {
1161
- throw new Error("fields is required");
1162
- }
1156
+ const { operationName, fields, datas, _set, where, variables, variableName } = input;
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
- finalVariables.datas = dataArray;
1169
- const datasArg = "$datas";
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}(${operationName}: ${datasArg}) {
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
- throw new Error("update mutation requires where condition");
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}) {