@ctil/gql 1.0.9 → 1.0.11
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 +23 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3736,6 +3736,8 @@ function buildDataValue(data) {
|
|
|
3736
3736
|
function formatGraphQLValue(value) {
|
|
3737
3737
|
if (value === null) return "null";
|
|
3738
3738
|
if (typeof value === "string") {
|
|
3739
|
+
if (value.startsWith("$")) return value;
|
|
3740
|
+
if (/^[A-Z0-9_]+$/.test(value)) return value;
|
|
3739
3741
|
return JSON.stringify(value);
|
|
3740
3742
|
}
|
|
3741
3743
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
@@ -3768,14 +3770,14 @@ function buildGraphQLQueryList(input) {
|
|
|
3768
3770
|
if (limit !== void 0) topArgs.push(`limit: ${limit}`);
|
|
3769
3771
|
if (offset !== void 0) topArgs.push(`offset: ${offset}`);
|
|
3770
3772
|
const topArgsStr = topArgs.length ? `(${topArgs.join(" ")})` : "";
|
|
3771
|
-
const query2 = `query ${operationName}${varDefs ? `(${varDefs})` : ""} { ${operationName}${topArgsStr} ${fields ? "{" + buildFields(fields) + "}" : ""} }`;
|
|
3773
|
+
const query2 = `query ${operationName.toLowerCase()}${varDefs ? `(${varDefs})` : ""} { ${operationName.toLowerCase()}${topArgsStr} ${fields ? "{" + buildFields(fields) + "}" : ""} }`;
|
|
3772
3774
|
return { query: query2, variables };
|
|
3773
3775
|
}
|
|
3774
3776
|
function buildGraphQLQueryByIdFixed(queryByIdInput) {
|
|
3775
3777
|
const { pk, fields, operationName } = queryByIdInput;
|
|
3776
3778
|
const variables = { id: pk };
|
|
3777
|
-
const query2 = `query ${operationName + "_by_pk"}($id: Long!) {
|
|
3778
|
-
${operationName + "_by_pk"}(id: $id) {
|
|
3779
|
+
const query2 = `query ${operationName.toLowerCase() + "_by_pk"}($id: Long!) {
|
|
3780
|
+
${operationName.toLowerCase() + "_by_pk"}(id: $id) {
|
|
3779
3781
|
${buildFields(fields)}
|
|
3780
3782
|
}
|
|
3781
3783
|
}`;
|
|
@@ -3794,7 +3796,7 @@ function buildGraphQLQueryPageList(input) {
|
|
|
3794
3796
|
if (size !== void 0) topArgs.push(`size: ${size}`);
|
|
3795
3797
|
if (page !== void 0) topArgs.push(`page: ${page}`);
|
|
3796
3798
|
const topArgsStr = topArgs.length ? `(${topArgs.join(" ")})` : "";
|
|
3797
|
-
const query2 = `query ${"get" +
|
|
3799
|
+
const query2 = `query ${"get" + operationName + "PageList"}${varDefs ? `(${varDefs})` : ""} { ${"get" + toPascalCase(operationName) + "PageList"}${topArgsStr} { hasMore list{${buildFields(fields)}} page size total } }`;
|
|
3798
3800
|
return { query: query2, variables };
|
|
3799
3801
|
}
|
|
3800
3802
|
function buildGraphQLQueryAggregate(input) {
|
|
@@ -3818,8 +3820,8 @@ function buildGraphQLQueryAggregate(input) {
|
|
|
3818
3820
|
}
|
|
3819
3821
|
const aggregateStr = aggregateParts.join(" ");
|
|
3820
3822
|
const query2 = `
|
|
3821
|
-
query ${operationName + "_aggregateount"}${varDefs ? `(${varDefs})` : ""} {
|
|
3822
|
-
${operationName}
|
|
3823
|
+
query ${operationName.toLowerCase() + "_aggregateount"}${varDefs ? `(${varDefs})` : ""} {
|
|
3824
|
+
${operationName.toLowerCase() + "_aggregateount"}${topArgsStr} {
|
|
3823
3825
|
aggregate { ${aggregateStr} }
|
|
3824
3826
|
nodes { ${buildFields(fields)} }
|
|
3825
3827
|
}
|
|
@@ -3831,7 +3833,7 @@ function buildGraphQLQueryAggregate(input) {
|
|
|
3831
3833
|
// src/builders/mutation.ts
|
|
3832
3834
|
function buildGraphQLMutationInsertOne(input) {
|
|
3833
3835
|
const { operationName, fields, data, variables } = input;
|
|
3834
|
-
const entityName = operationName
|
|
3836
|
+
const entityName = operationName;
|
|
3835
3837
|
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
3836
3838
|
let dataArg;
|
|
3837
3839
|
if (variables && variables.data) {
|
|
@@ -3843,7 +3845,7 @@ function buildGraphQLMutationInsertOne(input) {
|
|
|
3843
3845
|
if (!variables || !variables.data) {
|
|
3844
3846
|
finalVariables.data = data;
|
|
3845
3847
|
}
|
|
3846
|
-
const mutationName = `insert_${entityName}_one`;
|
|
3848
|
+
const mutationName = `insert_${entityName.toLowerCase()}_one`;
|
|
3847
3849
|
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
3848
3850
|
${mutationName}(${operationName}: ${dataArg}) {
|
|
3849
3851
|
${buildMutationFields(fields)}
|
|
@@ -3853,7 +3855,7 @@ function buildGraphQLMutationInsertOne(input) {
|
|
|
3853
3855
|
}
|
|
3854
3856
|
function buildGraphQLMutationBatchInsert(input) {
|
|
3855
3857
|
const { operationName, fields, datas, variables } = input;
|
|
3856
|
-
const entityName = operationName
|
|
3858
|
+
const entityName = operationName;
|
|
3857
3859
|
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
3858
3860
|
let datasArg;
|
|
3859
3861
|
if (variables && variables.datas) {
|
|
@@ -3866,7 +3868,7 @@ function buildGraphQLMutationBatchInsert(input) {
|
|
|
3866
3868
|
if (!variables || !variables.datas) {
|
|
3867
3869
|
finalVariables.datas = datas;
|
|
3868
3870
|
}
|
|
3869
|
-
const mutationName = `insert_${entityName}s`;
|
|
3871
|
+
const mutationName = `insert_${entityName.toLowerCase()}s`;
|
|
3870
3872
|
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
3871
3873
|
${mutationName}(${operationName}s: ${datasArg}) {
|
|
3872
3874
|
affected_rows
|
|
@@ -3877,7 +3879,7 @@ function buildGraphQLMutationBatchInsert(input) {
|
|
|
3877
3879
|
}
|
|
3878
3880
|
function buildGraphQLMutationUpdate(input) {
|
|
3879
3881
|
const { operationName, fields, _set, where, variables } = input;
|
|
3880
|
-
const entityName = operationName
|
|
3882
|
+
const entityName = operationName;
|
|
3881
3883
|
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
3882
3884
|
const args = [];
|
|
3883
3885
|
let setArg;
|
|
@@ -3892,7 +3894,7 @@ function buildGraphQLMutationUpdate(input) {
|
|
|
3892
3894
|
if (!variables || !variables._set) {
|
|
3893
3895
|
finalVariables._set = _set;
|
|
3894
3896
|
}
|
|
3895
|
-
const mutationName = `update_${entityName}`;
|
|
3897
|
+
const mutationName = `update_${entityName.toLowerCase()}`;
|
|
3896
3898
|
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
3897
3899
|
${mutationName}(${args.join(", ")}) {
|
|
3898
3900
|
${buildMutationFields(fields)}
|
|
@@ -3902,7 +3904,7 @@ function buildGraphQLMutationUpdate(input) {
|
|
|
3902
3904
|
}
|
|
3903
3905
|
function buildGraphQLMutationBatchUpdate(input) {
|
|
3904
3906
|
const { operationName, fields, _set, variables } = input;
|
|
3905
|
-
const entityName = operationName
|
|
3907
|
+
const entityName = operationName;
|
|
3906
3908
|
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
3907
3909
|
let setArg;
|
|
3908
3910
|
if (variables && variables._set) {
|
|
@@ -3915,7 +3917,7 @@ function buildGraphQLMutationBatchUpdate(input) {
|
|
|
3915
3917
|
if (!variables || !variables._set) {
|
|
3916
3918
|
finalVariables._set = _set;
|
|
3917
3919
|
}
|
|
3918
|
-
const mutationName = `update_${entityName}_many`;
|
|
3920
|
+
const mutationName = `update_${entityName.toLowerCase()}_many`;
|
|
3919
3921
|
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
3920
3922
|
${mutationName}(_set: ${setArg}) {
|
|
3921
3923
|
affected_rows
|
|
@@ -3926,7 +3928,7 @@ function buildGraphQLMutationBatchUpdate(input) {
|
|
|
3926
3928
|
}
|
|
3927
3929
|
function buildGraphQLMutationUpdateByPk(input) {
|
|
3928
3930
|
const { operationName, fields, _set, pk_columns, variables } = input;
|
|
3929
|
-
const entityName = operationName
|
|
3931
|
+
const entityName = operationName;
|
|
3930
3932
|
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
3931
3933
|
const args = [];
|
|
3932
3934
|
let setArg;
|
|
@@ -3941,7 +3943,7 @@ function buildGraphQLMutationUpdateByPk(input) {
|
|
|
3941
3943
|
if (!variables || !variables._set) {
|
|
3942
3944
|
finalVariables._set = _set;
|
|
3943
3945
|
}
|
|
3944
|
-
const mutationName = `update_${entityName}_by_pk`;
|
|
3946
|
+
const mutationName = `update_${entityName.toLowerCase()}_by_pk`;
|
|
3945
3947
|
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
3946
3948
|
${mutationName}(${args.join(", ")}) {
|
|
3947
3949
|
${buildMutationFields(fields)}
|
|
@@ -3951,10 +3953,10 @@ function buildGraphQLMutationUpdateByPk(input) {
|
|
|
3951
3953
|
}
|
|
3952
3954
|
function buildGraphQLMutationDeleteById(input) {
|
|
3953
3955
|
const { operationName, fields, pk_columns, variables } = input;
|
|
3954
|
-
const entityName = operationName
|
|
3956
|
+
const entityName = operationName;
|
|
3955
3957
|
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
3956
3958
|
const args = `pk_columns: ${formatGraphQLValue(pk_columns)}`;
|
|
3957
|
-
const mutationName = `delete_${entityName}_by_pk`;
|
|
3959
|
+
const mutationName = `delete_${entityName.toLowerCase()}_by_pk`;
|
|
3958
3960
|
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
3959
3961
|
${mutationName}(${args}) {
|
|
3960
3962
|
${buildMutationFields(fields)}
|
|
@@ -3964,10 +3966,10 @@ function buildGraphQLMutationDeleteById(input) {
|
|
|
3964
3966
|
}
|
|
3965
3967
|
function buildGraphQLMutationDelete(input) {
|
|
3966
3968
|
const { operationName, fields, where, variables } = input;
|
|
3967
|
-
const entityName = operationName
|
|
3969
|
+
const entityName = operationName;
|
|
3968
3970
|
const varDefs = variables ? Object.keys(variables).map((k) => `$${k}: String!`).join(", ") : "";
|
|
3969
3971
|
const args = `where: { ${buildWhere(where)} }`;
|
|
3970
|
-
const mutationName = `delete_${entityName}`;
|
|
3972
|
+
const mutationName = `delete_${entityName.toLowerCase()}`;
|
|
3971
3973
|
const query2 = `mutation ${mutationName}${varDefs ? `(${varDefs})` : ""} {
|
|
3972
3974
|
${mutationName}(${args}) {
|
|
3973
3975
|
affected_rows
|
|
@@ -4547,6 +4549,7 @@ var clearHeaders = () => getClient().clearHeaders();
|
|
|
4547
4549
|
var query = {
|
|
4548
4550
|
async list(input, useCache = true, ttl) {
|
|
4549
4551
|
return rateLimit("list", "query", async () => {
|
|
4552
|
+
input.operationName = input.operationName + "s";
|
|
4550
4553
|
const { query: q, variables } = buildGraphQLQueryList(input);
|
|
4551
4554
|
const key = getCacheKey(q, variables);
|
|
4552
4555
|
if (useCache) {
|