@smartive/graphql-magic 23.10.0 → 23.11.0-next.1
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/.github/workflows/docs.yml +1 -1
- package/.github/workflows/release.yml +1 -1
- package/CHANGELOG.md +2 -2
- package/dist/bin/gqm.cjs +4 -2
- package/dist/cjs/index.cjs +10 -4
- package/dist/esm/models/model-definitions.d.ts +2 -0
- package/dist/esm/models/models.d.ts +2 -0
- package/dist/esm/models/models.js.map +1 -1
- package/dist/esm/models/mutation-hook.d.ts +4 -1
- package/dist/esm/resolvers/mutations.js +6 -2
- package/dist/esm/resolvers/mutations.js.map +1 -1
- package/dist/esm/schema/generate.js +2 -0
- package/dist/esm/schema/generate.js.map +1 -1
- package/docker-compose.yml +1 -1
- package/docs/package-lock.json +3423 -2391
- package/package.json +1 -1
- package/src/models/model-definitions.ts +14 -2
- package/src/models/models.ts +14 -2
- package/src/models/mutation-hook.ts +2 -1
- package/src/resolvers/mutations.ts +6 -2
- package/src/schema/generate.ts +2 -0
package/package.json
CHANGED
|
@@ -145,8 +145,20 @@ export type ModelDefinition = {
|
|
|
145
145
|
interfaces?: readonly string[];
|
|
146
146
|
queriable?: boolean;
|
|
147
147
|
listQueriable?: boolean | { args?: readonly Field[] };
|
|
148
|
-
creatable?:
|
|
149
|
-
|
|
148
|
+
creatable?:
|
|
149
|
+
| boolean
|
|
150
|
+
| {
|
|
151
|
+
createdBy?: Partial<RelationFieldDefinition>;
|
|
152
|
+
createdAt?: Partial<DateTimeFieldDefinition>;
|
|
153
|
+
args?: readonly Field[];
|
|
154
|
+
};
|
|
155
|
+
updatable?:
|
|
156
|
+
| boolean
|
|
157
|
+
| {
|
|
158
|
+
updatedBy?: Partial<RelationFieldDefinition>;
|
|
159
|
+
updatedAt?: Partial<DateTimeFieldDefinition>;
|
|
160
|
+
args?: readonly Field[];
|
|
161
|
+
};
|
|
150
162
|
deletable?:
|
|
151
163
|
| boolean
|
|
152
164
|
| {
|
package/src/models/models.ts
CHANGED
|
@@ -344,8 +344,20 @@ export class EntityModel extends Model {
|
|
|
344
344
|
interfaces?: string[];
|
|
345
345
|
queriable?: boolean;
|
|
346
346
|
listQueriable?: boolean | { args?: readonly Field[] };
|
|
347
|
-
creatable?:
|
|
348
|
-
|
|
347
|
+
creatable?:
|
|
348
|
+
| boolean
|
|
349
|
+
| {
|
|
350
|
+
createdBy?: Partial<RelationFieldDefinition>;
|
|
351
|
+
createdAt?: Partial<DateTimeFieldDefinition>;
|
|
352
|
+
args?: readonly Field[];
|
|
353
|
+
};
|
|
354
|
+
updatable?:
|
|
355
|
+
| boolean
|
|
356
|
+
| {
|
|
357
|
+
updatedBy?: Partial<RelationFieldDefinition>;
|
|
358
|
+
updatedAt?: Partial<DateTimeFieldDefinition>;
|
|
359
|
+
args?: readonly Field[];
|
|
360
|
+
};
|
|
349
361
|
deletable?:
|
|
350
362
|
| boolean
|
|
351
363
|
| {
|
|
@@ -11,7 +11,7 @@ export type Trigger = 'mutation' | 'direct-call' | 'cascade' | 'set-null';
|
|
|
11
11
|
export type MutationContext<DateType extends AnyDateType = AnyDateType> = Pick<
|
|
12
12
|
Context<DateType>,
|
|
13
13
|
'knex' | 'now' | 'user' | 'timeZone' | 'mutationHook' | 'models' | 'permissions'
|
|
14
|
-
|
|
14
|
+
> & { args?: Record<string, unknown> };
|
|
15
15
|
|
|
16
16
|
export type MutationHook<DateType extends AnyDateType = AnyDateType> = (args: {
|
|
17
17
|
model: EntityModel;
|
|
@@ -19,6 +19,7 @@ export type MutationHook<DateType extends AnyDateType = AnyDateType> = (args: {
|
|
|
19
19
|
trigger: Trigger;
|
|
20
20
|
when: 'before' | 'after';
|
|
21
21
|
data: { prev: Entity; input: Entity; normalizedInput: Entity; next: Entity };
|
|
22
|
+
args?: Record<string, unknown>;
|
|
22
23
|
ctx: MutationContext<DateType>;
|
|
23
24
|
}) => Promise<void> | void;
|
|
24
25
|
|
|
@@ -18,14 +18,14 @@ export const mutationResolver = async (_parent: any, args: any, partialCtx: Cont
|
|
|
18
18
|
const [, mutation, modelName] = it(info.fieldName.match(/^(create|update|delete|restore)(.+)$/));
|
|
19
19
|
switch (mutation) {
|
|
20
20
|
case 'create': {
|
|
21
|
-
const id = await createEntity(modelName, args.data, ctx, 'mutation');
|
|
21
|
+
const id = await createEntity(modelName, args.data, { ...ctx, args }, 'mutation');
|
|
22
22
|
|
|
23
23
|
return await resolve(ctx, id);
|
|
24
24
|
}
|
|
25
25
|
case 'update': {
|
|
26
26
|
const id = args.where.id;
|
|
27
27
|
|
|
28
|
-
await updateEntity(modelName, id, args.data, ctx, 'mutation');
|
|
28
|
+
await updateEntity(modelName, id, args.data, { ...ctx, args }, 'mutation');
|
|
29
29
|
|
|
30
30
|
return await resolve(ctx, id);
|
|
31
31
|
}
|
|
@@ -81,6 +81,7 @@ export const createEntity = async (
|
|
|
81
81
|
trigger,
|
|
82
82
|
when: 'before',
|
|
83
83
|
data: { prev: {}, input, normalizedInput, next: normalizedInput },
|
|
84
|
+
args: ctx.args ?? {},
|
|
84
85
|
ctx,
|
|
85
86
|
});
|
|
86
87
|
|
|
@@ -114,6 +115,7 @@ export const createEntity = async (
|
|
|
114
115
|
trigger,
|
|
115
116
|
when: 'after',
|
|
116
117
|
data: { prev: {}, input, normalizedInput, next: normalizedInput },
|
|
118
|
+
args: ctx.args ?? {},
|
|
117
119
|
ctx,
|
|
118
120
|
});
|
|
119
121
|
|
|
@@ -164,6 +166,7 @@ export const updateEntity = async (
|
|
|
164
166
|
trigger,
|
|
165
167
|
when: 'before',
|
|
166
168
|
data: { prev: currentEntity, input, normalizedInput, next: { ...currentEntity, ...normalizedInput } },
|
|
169
|
+
args: ctx.args ?? {},
|
|
167
170
|
ctx,
|
|
168
171
|
});
|
|
169
172
|
await doUpdate(model, currentEntity, normalizedInput, ctx);
|
|
@@ -173,6 +176,7 @@ export const updateEntity = async (
|
|
|
173
176
|
trigger,
|
|
174
177
|
when: 'after',
|
|
175
178
|
data: { prev: currentEntity, input, normalizedInput, next: { ...currentEntity, ...normalizedInput } },
|
|
179
|
+
args: ctx.args ?? {},
|
|
176
180
|
ctx,
|
|
177
181
|
});
|
|
178
182
|
}
|
package/src/schema/generate.ts
CHANGED
|
@@ -249,6 +249,7 @@ export const generateDefinitions = ({
|
|
|
249
249
|
type: `Create${model.name}`,
|
|
250
250
|
nonNull: true,
|
|
251
251
|
},
|
|
252
|
+
...((model.creatable && model.creatable !== true && model.creatable.args) || []),
|
|
252
253
|
],
|
|
253
254
|
});
|
|
254
255
|
}
|
|
@@ -269,6 +270,7 @@ export const generateDefinitions = ({
|
|
|
269
270
|
type: `Update${model.name}`,
|
|
270
271
|
nonNull: true,
|
|
271
272
|
},
|
|
273
|
+
...((model.updatable && model.updatable !== true && model.updatable.args) || []),
|
|
272
274
|
],
|
|
273
275
|
});
|
|
274
276
|
}
|