@smartive/graphql-magic 21.0.0-next.5 → 21.0.0
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/.releaserc +7 -1
- package/CHANGELOG.md +6 -3
- package/dist/cjs/index.cjs +0 -38
- package/dist/esm/client/queries.d.ts +0 -8
- package/dist/esm/client/queries.js +1 -44
- package/dist/esm/client/queries.js.map +1 -1
- package/package.json +4 -4
- package/src/client/queries.ts +1 -70
package/.releaserc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
## 21.0.0
|
|
1
|
+
## 21.0.0 (2025-09-22)
|
|
2
2
|
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* break: Schema validation (#351) ([5512f6d](https://github.com/smartive/graphql-magic/commit/5512f6d)), closes [#351](https://github.com/smartive/graphql-magic/issues/351)
|
|
4
|
+
* chore(deps): update dependency esbuild to v0.25.10 (#352) ([eb9d165](https://github.com/smartive/graphql-magic/commit/eb9d165)), closes [#352](https://github.com/smartive/graphql-magic/issues/352)
|
|
5
|
+
* chore(deps): update dependency eslint to v9.36.0 (#356) ([8d3794d](https://github.com/smartive/graphql-magic/commit/8d3794d)), closes [#356](https://github.com/smartive/graphql-magic/issues/356)
|
|
6
|
+
* chore(deps): update dependency ts-jest to v29.4.3 (#353) ([3d70b79](https://github.com/smartive/graphql-magic/commit/3d70b79)), closes [#353](https://github.com/smartive/graphql-magic/issues/353)
|
|
7
|
+
* chore(deps): update dependency ts-jest to v29.4.4 (#355) ([3e9f40e](https://github.com/smartive/graphql-magic/commit/3e9f40e)), closes [#355](https://github.com/smartive/graphql-magic/issues/355)
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -96,7 +96,6 @@ __export(index_exports, {
|
|
|
96
96
|
getColumnName: () => getColumnName,
|
|
97
97
|
getDisplay: () => getDisplay,
|
|
98
98
|
getEntityToMutate: () => getEntityToMutate,
|
|
99
|
-
getFindEntityQuery: () => getFindEntityQuery,
|
|
100
99
|
getFragmentSpreads: () => getFragmentSpreads,
|
|
101
100
|
getFragmentTypeName: () => getFragmentTypeName,
|
|
102
101
|
getInlineFragments: () => getInlineFragments,
|
|
@@ -105,7 +104,6 @@ __export(index_exports, {
|
|
|
105
104
|
getManyToManyDisplay: () => getManyToManyDisplay,
|
|
106
105
|
getManyToManyRelationsQuery: () => getManyToManyRelationsQuery,
|
|
107
106
|
getMigrationDate: () => getMigrationDate,
|
|
108
|
-
getMutationQuery: () => getMutationQuery,
|
|
109
107
|
getNameOrAlias: () => getNameOrAlias,
|
|
110
108
|
getPermissionStack: () => getPermissionStack,
|
|
111
109
|
getResolverNode: () => getResolverNode,
|
|
@@ -117,7 +115,6 @@ __export(index_exports, {
|
|
|
117
115
|
getTechnicalDisplay: () => getTechnicalDisplay,
|
|
118
116
|
getType: () => getType,
|
|
119
117
|
getTypeName: () => getTypeName,
|
|
120
|
-
getUpdateEntityQuery: () => getUpdateEntityQuery,
|
|
121
118
|
gql: () => gql,
|
|
122
119
|
hasName: () => hasName,
|
|
123
120
|
hash: () => hash,
|
|
@@ -887,14 +884,6 @@ var as = (value2, type) => {
|
|
|
887
884
|
};
|
|
888
885
|
|
|
889
886
|
// src/client/queries.ts
|
|
890
|
-
var getUpdateEntityQuery = (model, role, fields2, additionalFields = "") => `query Update${model.name}Fields ($id: ID!) {
|
|
891
|
-
data: ${typeToField(model.name)}(where: { id: $id }) {
|
|
892
|
-
id
|
|
893
|
-
${model.fields.filter(({ name: name2 }) => !fields2 || fields2.includes(name2)).filter(not(isRelation)).filter(isUpdatableBy(role)).map(({ name: name2 }) => name2).join(" ")}
|
|
894
|
-
${getActionableRelations(model, "update").filter((name2) => !fields2 || fields2.includes(name2)).map((name2) => `${name2} { id, display: ${model.getRelation(name2).targetModel.displayField || "id"} }`)}
|
|
895
|
-
${additionalFields}
|
|
896
|
-
}
|
|
897
|
-
}`;
|
|
898
887
|
var fieldIsSearchable = (model, fieldName) => {
|
|
899
888
|
const relation = model.getRelation(fieldName);
|
|
900
889
|
const targetModel = relation.targetModel;
|
|
@@ -926,33 +915,9 @@ var getManyToManyRelationsQuery = (model, action, manyToManyRelations) => !!many
|
|
|
926
915
|
}`;
|
|
927
916
|
}).join(" ")}
|
|
928
917
|
}`);
|
|
929
|
-
var getMutationQuery = (model, action) => action === "create" ? `
|
|
930
|
-
mutation Create${model.name} ($data: Create${model.name}!) {
|
|
931
|
-
mutated: create${model.name}(data: $data) {
|
|
932
|
-
id
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
` : action === "update" ? `
|
|
936
|
-
mutation Update${model.name} ($id: ID!, $data: Update${model.name}!) {
|
|
937
|
-
mutated: update${model.name}(where: { id: $id } data: $data) {
|
|
938
|
-
id
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
` : `
|
|
942
|
-
mutation Delete${model.name} ($id: ID!) {
|
|
943
|
-
mutated: delete${model.name}(where: { id: $id }) {
|
|
944
|
-
id
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
`;
|
|
948
918
|
var displayField = (model) => `
|
|
949
919
|
${model.displayField ? `display: ${model.displayField}` : ""}
|
|
950
920
|
`;
|
|
951
|
-
var getFindEntityQuery = (model, role) => `query Find${model.name}($where: ${model.name}Where!, $orderBy: [${model.name}OrderBy!]) {
|
|
952
|
-
data: ${model.pluralField}(limit: 1, where: $where, orderBy: $orderBy) {
|
|
953
|
-
${model.fields.filter(and(isSimpleField, isQueriableBy(role))).map(({ name: name2 }) => name2)}
|
|
954
|
-
}
|
|
955
|
-
}`;
|
|
956
921
|
var queryRelations = (models, relations) => relations.map(
|
|
957
922
|
(relation) => `${relation.name} {
|
|
958
923
|
id
|
|
@@ -3776,7 +3741,6 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql6.buildAST
|
|
|
3776
3741
|
getColumnName,
|
|
3777
3742
|
getDisplay,
|
|
3778
3743
|
getEntityToMutate,
|
|
3779
|
-
getFindEntityQuery,
|
|
3780
3744
|
getFragmentSpreads,
|
|
3781
3745
|
getFragmentTypeName,
|
|
3782
3746
|
getInlineFragments,
|
|
@@ -3785,7 +3749,6 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql6.buildAST
|
|
|
3785
3749
|
getManyToManyDisplay,
|
|
3786
3750
|
getManyToManyRelationsQuery,
|
|
3787
3751
|
getMigrationDate,
|
|
3788
|
-
getMutationQuery,
|
|
3789
3752
|
getNameOrAlias,
|
|
3790
3753
|
getPermissionStack,
|
|
3791
3754
|
getResolverNode,
|
|
@@ -3797,7 +3760,6 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql6.buildAST
|
|
|
3797
3760
|
getTechnicalDisplay,
|
|
3798
3761
|
getType,
|
|
3799
3762
|
getTypeName,
|
|
3800
|
-
getUpdateEntityQuery,
|
|
3801
3763
|
gql,
|
|
3802
3764
|
hasName,
|
|
3803
3765
|
hash,
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { ManyToManyRelation } from '..';
|
|
2
2
|
import { EntityModel, Model, Models, Relation } from '../models/models';
|
|
3
|
-
export declare const getUpdateEntityQuery: (model: EntityModel, role: string, fields?: string[], additionalFields?: string) => string;
|
|
4
3
|
export type RelationConstraints = Record<string, (source: any) => any>;
|
|
5
4
|
export declare const fieldIsSearchable: (model: EntityModel, fieldName: string) => boolean | undefined;
|
|
6
5
|
export declare const getManyToManyRelationsQuery: (model: Model, action: "create" | "update", manyToManyRelations: ManyToManyRelation[]) => string | false;
|
|
7
|
-
export type MutationQuery = {
|
|
8
|
-
mutated: {
|
|
9
|
-
id: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export declare const getMutationQuery: (model: Model, action: "create" | "update" | "delete") => string;
|
|
13
6
|
export declare const displayField: (model: EntityModel) => string;
|
|
14
|
-
export declare const getFindEntityQuery: (model: EntityModel, role: string) => string;
|
|
15
7
|
export declare const queryRelations: (models: Models, relations: Relation[]) => string;
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const getUpdateEntityQuery = (model, role, fields, additionalFields = '') => `query Update${model.name}Fields ($id: ID!) {
|
|
3
|
-
data: ${typeToField(model.name)}(where: { id: $id }) {
|
|
4
|
-
id
|
|
5
|
-
${model.fields
|
|
6
|
-
.filter(({ name }) => !fields || fields.includes(name))
|
|
7
|
-
.filter(not(isRelation))
|
|
8
|
-
.filter(isUpdatableBy(role))
|
|
9
|
-
.map(({ name }) => name)
|
|
10
|
-
.join(' ')}
|
|
11
|
-
${getActionableRelations(model, 'update')
|
|
12
|
-
.filter((name) => !fields || fields.includes(name))
|
|
13
|
-
.map((name) => `${name} { id, display: ${model.getRelation(name).targetModel.displayField || 'id'} }`)}
|
|
14
|
-
${additionalFields}
|
|
15
|
-
}
|
|
16
|
-
}`;
|
|
1
|
+
import { typeToField } from '../models/utils';
|
|
17
2
|
export const fieldIsSearchable = (model, fieldName) => {
|
|
18
3
|
const relation = model.getRelation(fieldName);
|
|
19
4
|
const targetModel = relation.targetModel;
|
|
@@ -54,37 +39,9 @@ export const getManyToManyRelationsQuery = (model, action, manyToManyRelations)
|
|
|
54
39
|
})
|
|
55
40
|
.join(' ')}
|
|
56
41
|
}`);
|
|
57
|
-
export const getMutationQuery = (model, action) => action === 'create'
|
|
58
|
-
? `
|
|
59
|
-
mutation Create${model.name} ($data: Create${model.name}!) {
|
|
60
|
-
mutated: create${model.name}(data: $data) {
|
|
61
|
-
id
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
`
|
|
65
|
-
: action === 'update'
|
|
66
|
-
? `
|
|
67
|
-
mutation Update${model.name} ($id: ID!, $data: Update${model.name}!) {
|
|
68
|
-
mutated: update${model.name}(where: { id: $id } data: $data) {
|
|
69
|
-
id
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
`
|
|
73
|
-
: `
|
|
74
|
-
mutation Delete${model.name} ($id: ID!) {
|
|
75
|
-
mutated: delete${model.name}(where: { id: $id }) {
|
|
76
|
-
id
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
`;
|
|
80
42
|
export const displayField = (model) => `
|
|
81
43
|
${model.displayField ? `display: ${model.displayField}` : ''}
|
|
82
44
|
`;
|
|
83
|
-
export const getFindEntityQuery = (model, role) => `query Find${model.name}($where: ${model.name}Where!, $orderBy: [${model.name}OrderBy!]) {
|
|
84
|
-
data: ${model.pluralField}(limit: 1, where: $where, orderBy: $orderBy) {
|
|
85
|
-
${model.fields.filter(and(isSimpleField, isQueriableBy(role))).map(({ name }) => name)}
|
|
86
|
-
}
|
|
87
|
-
}`;
|
|
88
45
|
export const queryRelations = (models, relations) => relations
|
|
89
46
|
.map((relation) => `${relation.name} {
|
|
90
47
|
id
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/client/queries.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/client/queries.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAkB,EAAE,SAAiB,EAAE,EAAE;IACzE,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC9C,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;IACzC,MAAM,YAAY,GAAG,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,IAAI,IAAI,CAAC,CAAC;IAE5E,OAAO,YAAY,CAAC,UAAU,CAAC;AACjC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,KAAY,EACZ,MAA2B,EAC3B,mBAAyC,EACzC,EAAE,CACF,CAAC,CAAC,mBAAmB,CAAC,MAAM;IAC5B,CAAC,MAAM,KAAK,QAAQ;QAClB,CAAC,CAAC,eAAe,KAAK,CAAC,IAAI;cAC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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartive/graphql-magic",
|
|
3
|
-
"version": "21.0.0
|
|
3
|
+
"version": "21.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
75
75
|
"create-ts-index": "1.14.0",
|
|
76
76
|
"del-cli": "6.0.0",
|
|
77
|
-
"esbuild": "0.25.
|
|
78
|
-
"eslint": "9.
|
|
77
|
+
"esbuild": "0.25.10",
|
|
78
|
+
"eslint": "9.36.0",
|
|
79
79
|
"jest": "29.7.0",
|
|
80
80
|
"mock-knex": "0.4.13",
|
|
81
81
|
"prettier": "3.6.2",
|
|
82
|
-
"ts-jest": "29.4.
|
|
82
|
+
"ts-jest": "29.4.4",
|
|
83
83
|
"ts-node": "10.9.2",
|
|
84
84
|
"typescript": "5.9.2"
|
|
85
85
|
}
|
package/src/client/queries.ts
CHANGED
|
@@ -1,36 +1,6 @@
|
|
|
1
1
|
import { ManyToManyRelation } from '..';
|
|
2
2
|
import { EntityModel, Model, Models, Relation } from '../models/models';
|
|
3
|
-
import {
|
|
4
|
-
and,
|
|
5
|
-
getActionableRelations,
|
|
6
|
-
isQueriableBy,
|
|
7
|
-
isRelation,
|
|
8
|
-
isSimpleField,
|
|
9
|
-
isUpdatableBy,
|
|
10
|
-
not,
|
|
11
|
-
typeToField,
|
|
12
|
-
} from '../models/utils';
|
|
13
|
-
|
|
14
|
-
export const getUpdateEntityQuery = (
|
|
15
|
-
model: EntityModel,
|
|
16
|
-
role: string,
|
|
17
|
-
fields?: string[],
|
|
18
|
-
additionalFields = '',
|
|
19
|
-
) => `query Update${model.name}Fields ($id: ID!) {
|
|
20
|
-
data: ${typeToField(model.name)}(where: { id: $id }) {
|
|
21
|
-
id
|
|
22
|
-
${model.fields
|
|
23
|
-
.filter(({ name }) => !fields || fields.includes(name))
|
|
24
|
-
.filter(not(isRelation))
|
|
25
|
-
.filter(isUpdatableBy(role))
|
|
26
|
-
.map(({ name }) => name)
|
|
27
|
-
.join(' ')}
|
|
28
|
-
${getActionableRelations(model, 'update')
|
|
29
|
-
.filter((name) => !fields || fields.includes(name))
|
|
30
|
-
.map((name) => `${name} { id, display: ${model.getRelation(name).targetModel.displayField || 'id'} }`)}
|
|
31
|
-
${additionalFields}
|
|
32
|
-
}
|
|
33
|
-
}`;
|
|
3
|
+
import { typeToField } from '../models/utils';
|
|
34
4
|
|
|
35
5
|
export type RelationConstraints = Record<string, (source: any) => any>;
|
|
36
6
|
|
|
@@ -82,49 +52,10 @@ export const getManyToManyRelationsQuery = (
|
|
|
82
52
|
.join(' ')}
|
|
83
53
|
}`);
|
|
84
54
|
|
|
85
|
-
export type MutationQuery = {
|
|
86
|
-
mutated: {
|
|
87
|
-
id: string;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const getMutationQuery = (model: Model, action: 'create' | 'update' | 'delete') =>
|
|
92
|
-
action === 'create'
|
|
93
|
-
? `
|
|
94
|
-
mutation Create${model.name} ($data: Create${model.name}!) {
|
|
95
|
-
mutated: create${model.name}(data: $data) {
|
|
96
|
-
id
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
`
|
|
100
|
-
: action === 'update'
|
|
101
|
-
? `
|
|
102
|
-
mutation Update${model.name} ($id: ID!, $data: Update${model.name}!) {
|
|
103
|
-
mutated: update${model.name}(where: { id: $id } data: $data) {
|
|
104
|
-
id
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
`
|
|
108
|
-
: `
|
|
109
|
-
mutation Delete${model.name} ($id: ID!) {
|
|
110
|
-
mutated: delete${model.name}(where: { id: $id }) {
|
|
111
|
-
id
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
`;
|
|
115
|
-
|
|
116
55
|
export const displayField = (model: EntityModel) => `
|
|
117
56
|
${model.displayField ? `display: ${model.displayField}` : ''}
|
|
118
57
|
`;
|
|
119
58
|
|
|
120
|
-
export const getFindEntityQuery = (model: EntityModel, role: string) => `query Find${model.name}($where: ${
|
|
121
|
-
model.name
|
|
122
|
-
}Where!, $orderBy: [${model.name}OrderBy!]) {
|
|
123
|
-
data: ${model.pluralField}(limit: 1, where: $where, orderBy: $orderBy) {
|
|
124
|
-
${model.fields.filter(and(isSimpleField, isQueriableBy(role))).map(({ name }) => name)}
|
|
125
|
-
}
|
|
126
|
-
}`;
|
|
127
|
-
|
|
128
59
|
export const queryRelations = (models: Models, relations: Relation[]) =>
|
|
129
60
|
relations
|
|
130
61
|
.map(
|