@smartive/graphql-magic 15.4.1 → 16.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/.gqmrc.json +4 -2
- package/CHANGELOG.md +1 -6
- package/dist/bin/gqm.cjs +115 -42
- package/dist/cjs/index.cjs +111 -30
- package/dist/esm/context.d.ts +5 -4
- package/dist/esm/db/generate.d.ts +2 -1
- package/dist/esm/db/generate.js +13 -8
- package/dist/esm/db/generate.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/migrations/generate.d.ts +1 -0
- package/dist/esm/migrations/generate.js +28 -6
- package/dist/esm/migrations/generate.js.map +1 -1
- package/dist/esm/models/mutation-hook.d.ts +5 -12
- package/dist/esm/models/utils.d.ts +18 -5
- package/dist/esm/models/utils.js +8 -0
- package/dist/esm/models/utils.js.map +1 -1
- package/dist/esm/permissions/check.d.ts +2 -3
- package/dist/esm/permissions/check.js.map +1 -1
- package/dist/esm/resolvers/arguments.d.ts +1 -1
- package/dist/esm/resolvers/mutations.js +5 -2
- package/dist/esm/resolvers/mutations.js.map +1 -1
- package/dist/esm/schema/utils.js +19 -8
- package/dist/esm/schema/utils.js.map +1 -1
- package/dist/esm/utils/dates.d.ts +12 -0
- package/dist/esm/utils/dates.js +37 -0
- package/dist/esm/utils/dates.js.map +1 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/values.d.ts +1 -3
- package/docker-compose.yml +0 -1
- package/docs/docs/1-tutorial.md +6 -6
- package/docs/docs/6-graphql-server.md +1 -3
- package/docs/docs/7-graphql-client.md +1 -1
- package/docs/docs/8-permissions.md +145 -0
- package/docs/package-lock.json +4 -4
- package/docs/package.json +1 -1
- package/knexfile.ts +2 -2
- package/migrations/20230912185644_setup.ts +37 -8
- package/package.json +5 -4
- package/src/bin/gqm/codegen.ts +4 -3
- package/src/bin/gqm/gqm.ts +4 -2
- package/src/bin/gqm/settings.ts +37 -2
- package/src/bin/gqm/templates.ts +19 -8
- package/src/context.ts +9 -5
- package/src/db/generate.ts +15 -8
- package/src/index.ts +1 -0
- package/src/migrations/generate.ts +34 -16
- package/src/models/mutation-hook.ts +5 -8
- package/src/models/utils.ts +24 -0
- package/src/permissions/check.ts +2 -3
- package/src/resolvers/mutations.ts +10 -6
- package/src/schema/utils.ts +14 -2
- package/src/utils/dates.ts +48 -0
- package/src/utils/index.ts +3 -0
- package/src/values.ts +1 -5
- package/tests/generated/client/index.ts +3 -1
- package/tests/generated/db/index.ts +43 -43
- package/tests/utils/database/seed.ts +9 -5
- package/tests/utils/server.ts +3 -3
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { EntityField, EntityModel, EnumModel, Models } from '../models/models';
|
|
|
8
8
|
import {
|
|
9
9
|
and,
|
|
10
10
|
get,
|
|
11
|
+
isCreatableModel,
|
|
11
12
|
isInherited,
|
|
12
13
|
isUpdatableField,
|
|
13
14
|
isUpdatableModel,
|
|
@@ -147,9 +148,7 @@ export class MigrationGenerator {
|
|
|
147
148
|
.filter(
|
|
148
149
|
({ name, ...field }) =>
|
|
149
150
|
field.kind !== 'custom' &&
|
|
150
|
-
!this.
|
|
151
|
-
(col) => col.name === (field.kind === 'relation' ? field.foreignKey || `${name}Id` : name)
|
|
152
|
-
)
|
|
151
|
+
!this.getColumn(model.name, field.kind === 'relation' ? field.foreignKey || `${name}Id` : name)
|
|
153
152
|
),
|
|
154
153
|
up,
|
|
155
154
|
down
|
|
@@ -157,7 +156,7 @@ export class MigrationGenerator {
|
|
|
157
156
|
|
|
158
157
|
// Update fields
|
|
159
158
|
const existingFields = model.fields.filter(({ name, kind, nonNull }) => {
|
|
160
|
-
const col = this.
|
|
159
|
+
const col = this.getColumn(model.name, kind === 'relation' ? `${name}Id` : name);
|
|
161
160
|
if (!col) {
|
|
162
161
|
return false;
|
|
163
162
|
}
|
|
@@ -216,9 +215,7 @@ export class MigrationGenerator {
|
|
|
216
215
|
.filter(
|
|
217
216
|
({ name, ...field }) =>
|
|
218
217
|
field.kind !== 'custom' &&
|
|
219
|
-
!this.
|
|
220
|
-
(col) => col.name === (field.kind === 'relation' ? field.foreignKey || `${name}Id` : name)
|
|
221
|
-
)
|
|
218
|
+
!this.getColumn(revisionTable, field.kind === 'relation' ? field.foreignKey || `${name}Id` : name)
|
|
222
219
|
);
|
|
223
220
|
|
|
224
221
|
this.createRevisionFields(model, missingRevisionFields, up, down);
|
|
@@ -229,9 +226,7 @@ export class MigrationGenerator {
|
|
|
229
226
|
field.kind !== 'custom' &&
|
|
230
227
|
!updatable &&
|
|
231
228
|
!(field.kind === 'relation' && field.foreignKey === 'id') &&
|
|
232
|
-
this.
|
|
233
|
-
(col) => col.name === (field.kind === 'relation' ? field.foreignKey || `${name}Id` : name)
|
|
234
|
-
)
|
|
229
|
+
this.getColumn(revisionTable, field.kind === 'relation' ? field.foreignKey || `${name}Id` : name)
|
|
235
230
|
);
|
|
236
231
|
this.createRevisionFields(model, revisionFieldsToRemove, down, up);
|
|
237
232
|
}
|
|
@@ -241,12 +236,31 @@ export class MigrationGenerator {
|
|
|
241
236
|
|
|
242
237
|
for (const model of models.entities) {
|
|
243
238
|
if (tables.includes(model.name)) {
|
|
244
|
-
this.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
239
|
+
const fieldsToDelete = model.fields.filter(({ name, deleted }) => deleted && this.getColumn(model.name, name));
|
|
240
|
+
|
|
241
|
+
if (!isCreatableModel(model)) {
|
|
242
|
+
if (this.getColumn(model.name, 'createdAt')) {
|
|
243
|
+
fieldsToDelete.push({ name: 'createdAt', type: 'DateTime', nonNull: true });
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (this.getColumn(model.name, 'createdBy')) {
|
|
247
|
+
fieldsToDelete.push({ name: 'createdBy', kind: 'relation', type: 'User', nonNull: true });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!isUpdatableModel(model)) {
|
|
252
|
+
if (this.getColumn(model.name, 'updatedAt')) {
|
|
253
|
+
fieldsToDelete.push({ name: 'updatedAt', type: 'DateTime', nonNull: true });
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (this.getColumn(model.name, 'updatedBy')) {
|
|
257
|
+
fieldsToDelete.push({ name: 'updatedBy', kind: 'relation', type: 'User', nonNull: true });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (fieldsToDelete.length) {
|
|
262
|
+
this.createFields(model, fieldsToDelete, down, up);
|
|
263
|
+
}
|
|
250
264
|
|
|
251
265
|
if (isUpdatableModel(model)) {
|
|
252
266
|
this.createRevisionFields(
|
|
@@ -664,6 +678,10 @@ export class MigrationGenerator {
|
|
|
664
678
|
}
|
|
665
679
|
}
|
|
666
680
|
}
|
|
681
|
+
|
|
682
|
+
private getColumn(tableName: string, columnName: string) {
|
|
683
|
+
return this.columns[tableName].find((col) => col.name === columnName);
|
|
684
|
+
}
|
|
667
685
|
}
|
|
668
686
|
|
|
669
687
|
export const getMigrationDate = () => {
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context } from '..';
|
|
1
|
+
import { AnyDateType, Context } from '..';
|
|
3
2
|
import { EntityModel } from './models';
|
|
4
3
|
|
|
5
|
-
export type Entity = Record<string, unknown
|
|
6
|
-
|
|
7
|
-
export type FullEntity = Entity & { id: string };
|
|
4
|
+
export type Entity = Record<string, unknown>;
|
|
8
5
|
|
|
9
6
|
export type Action = 'create' | 'update' | 'delete' | 'restore';
|
|
10
7
|
|
|
11
|
-
export type MutationHook = (
|
|
8
|
+
export type MutationHook<DateType extends AnyDateType = AnyDateType> = (
|
|
12
9
|
model: EntityModel,
|
|
13
10
|
action: Action,
|
|
14
11
|
when: 'before' | 'after',
|
|
15
|
-
data: { prev: Entity; input: Entity; normalizedInput: Entity; next:
|
|
16
|
-
ctx: Context
|
|
12
|
+
data: { prev: Entity; input: Entity; normalizedInput: Entity; next: Entity },
|
|
13
|
+
ctx: Context<DateType>
|
|
17
14
|
) => Promise<void>;
|
package/src/models/utils.ts
CHANGED
|
@@ -58,8 +58,12 @@ export const isInputModel = (model: Model): model is InputModel => model instanc
|
|
|
58
58
|
|
|
59
59
|
export const isInterfaceModel = (model: Model): model is InterfaceModel => model instanceof InterfaceModel;
|
|
60
60
|
|
|
61
|
+
export const isCreatableModel = (model: EntityModel) => model.creatable && model.fields.some(isCreatableField);
|
|
62
|
+
|
|
61
63
|
export const isUpdatableModel = (model: EntityModel) => model.updatable && model.fields.some(isUpdatableField);
|
|
62
64
|
|
|
65
|
+
export const isCreatableField = (field: EntityField) => !field.inherited && !!field.creatable;
|
|
66
|
+
|
|
63
67
|
export const isUpdatableField = (field: EntityField) => !field.inherited && !!field.updatable;
|
|
64
68
|
|
|
65
69
|
export const modelNeedsTable = (model: EntityModel) => model.fields.some((field) => !field.inherited);
|
|
@@ -169,3 +173,23 @@ export const retry = async <T>(cb: () => Promise<T>, condition: (e: any) => bool
|
|
|
169
173
|
}
|
|
170
174
|
}
|
|
171
175
|
};
|
|
176
|
+
|
|
177
|
+
type Typeof = {
|
|
178
|
+
string: string;
|
|
179
|
+
number: number;
|
|
180
|
+
bigint: bigint;
|
|
181
|
+
boolean: boolean;
|
|
182
|
+
symbol: symbol;
|
|
183
|
+
undefined: undefined;
|
|
184
|
+
object: object;
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
186
|
+
function: Function;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const as = <T extends keyof Typeof>(value: unknown, type: T): Typeof[T] => {
|
|
190
|
+
if (typeof value !== type) {
|
|
191
|
+
throw new Error(`No string`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return value as Typeof[T];
|
|
195
|
+
};
|
package/src/permissions/check.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { NotFoundError, PermissionError } from '../errors';
|
|
|
4
4
|
import { EntityModel } from '../models/models';
|
|
5
5
|
import { get, isRelation } from '../models/utils';
|
|
6
6
|
import { AliasGenerator, hash, ors } from '../resolvers/utils';
|
|
7
|
-
import { BasicValue } from '../values';
|
|
8
7
|
import { PermissionAction, PermissionLink, PermissionStack } from './generate';
|
|
9
8
|
|
|
10
9
|
export const getRole = (ctx: Pick<FullContext, 'user'>) => ctx.user?.role ?? 'UNAUTHENTICATED';
|
|
@@ -89,7 +88,7 @@ export const applyPermissions = (
|
|
|
89
88
|
export const getEntityToMutate = async (
|
|
90
89
|
ctx: Pick<FullContext, 'models' | 'permissions' | 'user' | 'knex'>,
|
|
91
90
|
model: EntityModel,
|
|
92
|
-
where: Record<string,
|
|
91
|
+
where: Record<string, unknown>,
|
|
93
92
|
action: 'UPDATE' | 'DELETE' | 'RESTORE'
|
|
94
93
|
) => {
|
|
95
94
|
const query = ctx
|
|
@@ -132,7 +131,7 @@ export const getEntityToMutate = async (
|
|
|
132
131
|
export const checkCanWrite = async (
|
|
133
132
|
ctx: Pick<FullContext, 'models' | 'permissions' | 'user' | 'knex'>,
|
|
134
133
|
model: EntityModel,
|
|
135
|
-
data: Record<string,
|
|
134
|
+
data: Record<string, unknown>,
|
|
136
135
|
action: 'CREATE' | 'UPDATE'
|
|
137
136
|
) => {
|
|
138
137
|
const permissionStack = getPermissionStack(ctx, model.name, action);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { GraphQLResolveInfo } from 'graphql';
|
|
2
|
-
import { DateTime } from 'luxon';
|
|
3
2
|
import { v4 as uuid } from 'uuid';
|
|
4
3
|
import { Context, FullContext } from '../context';
|
|
5
4
|
import { ForbiddenError, GraphQLError } from '../errors';
|
|
6
5
|
import { EntityField, EntityModel } from '../models/models';
|
|
7
|
-
import { Entity
|
|
6
|
+
import { Entity } from '../models/mutation-hook';
|
|
8
7
|
import { get, isPrimitive, it, typeToField } from '../models/utils';
|
|
9
8
|
import { applyPermissions, checkCanWrite, getEntityToMutate } from '../permissions/check';
|
|
9
|
+
import { anyDateToLuxon } from '../utils';
|
|
10
10
|
import { resolve } from './resolver';
|
|
11
11
|
import { AliasGenerator } from './utils';
|
|
12
12
|
|
|
@@ -151,7 +151,7 @@ const del = async (model: EntityModel, { where, dryRun }: { where: any; dryRun:
|
|
|
151
151
|
const mutations: Callbacks = [];
|
|
152
152
|
const afterHooks: Callbacks = [];
|
|
153
153
|
|
|
154
|
-
const deleteCascade = async (currentModel: EntityModel, entity:
|
|
154
|
+
const deleteCascade = async (currentModel: EntityModel, entity: Entity) => {
|
|
155
155
|
if (entity.deleted) {
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
@@ -266,8 +266,12 @@ const restore = async (model: EntityModel, { where }: { where: any }, ctx: FullC
|
|
|
266
266
|
const mutations: Callbacks = [];
|
|
267
267
|
const afterHooks: Callbacks = [];
|
|
268
268
|
|
|
269
|
-
const restoreCascade = async (currentModel: EntityModel, relatedEntity:
|
|
270
|
-
if (
|
|
269
|
+
const restoreCascade = async (currentModel: EntityModel, relatedEntity: Entity) => {
|
|
270
|
+
if (
|
|
271
|
+
!relatedEntity.deleted ||
|
|
272
|
+
!relatedEntity.deletedAt ||
|
|
273
|
+
anyDateToLuxon(relatedEntity.deletedAt, ctx.timeZone).equals(anyDateToLuxon(entity.deletedAt, ctx.timeZone))
|
|
274
|
+
) {
|
|
271
275
|
return;
|
|
272
276
|
}
|
|
273
277
|
|
|
@@ -365,7 +369,7 @@ const sanitize = (ctx: FullContext, model: EntityModel, data: Entity) => {
|
|
|
365
369
|
}
|
|
366
370
|
|
|
367
371
|
if (isEndOfDay(field) && data[key]) {
|
|
368
|
-
data[key] = (data[key]
|
|
372
|
+
data[key] = anyDateToLuxon(data[key], ctx.timeZone);
|
|
369
373
|
continue;
|
|
370
374
|
}
|
|
371
375
|
|
package/src/schema/utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
1
2
|
import {
|
|
2
3
|
ArgumentNode,
|
|
3
4
|
DefinitionNode,
|
|
@@ -222,7 +223,13 @@ export const value = (val: Value = null): ValueNode =>
|
|
|
222
223
|
kind: 'StringValue',
|
|
223
224
|
value: val.toString(),
|
|
224
225
|
}
|
|
225
|
-
:
|
|
226
|
+
: val instanceof Dayjs
|
|
227
|
+
? {
|
|
228
|
+
kind: 'StringValue',
|
|
229
|
+
value: val.toISOString(),
|
|
230
|
+
}
|
|
231
|
+
: typeof val === 'object'
|
|
232
|
+
? {
|
|
226
233
|
kind: 'ObjectValue',
|
|
227
234
|
fields: Object.keys(val).map(
|
|
228
235
|
(nme): ObjectFieldNode => ({
|
|
@@ -231,4 +238,9 @@ export const value = (val: Value = null): ValueNode =>
|
|
|
231
238
|
value: value(val[nme]),
|
|
232
239
|
})
|
|
233
240
|
),
|
|
234
|
-
}
|
|
241
|
+
}
|
|
242
|
+
: doThrow(`Unsupported value ${val}`);
|
|
243
|
+
|
|
244
|
+
const doThrow = (message: string) => {
|
|
245
|
+
throw new Error(message);
|
|
246
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Dayjs, isDayjs } from 'dayjs';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
|
|
4
|
+
export type DateLibrary = 'luxon' | 'dayjs';
|
|
5
|
+
|
|
6
|
+
export const DATE_CLASS: { [key in DateLibrary]: string } = {
|
|
7
|
+
luxon: 'DateTime',
|
|
8
|
+
dayjs: 'Dayjs',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const DATE_CLASS_IMPORT = {
|
|
12
|
+
luxon: `import { DateTime } from 'luxon';`,
|
|
13
|
+
dayjs: `import { Dayjs } from 'dayjs';`,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type AnyDateType = DateTime | Dayjs | Date | string;
|
|
17
|
+
|
|
18
|
+
export const anyDateToLuxon = (date: unknown, zone: string | undefined, fallbackToNow = false) => {
|
|
19
|
+
if (!date) {
|
|
20
|
+
if (fallbackToNow) {
|
|
21
|
+
return DateTime.local({ zone });
|
|
22
|
+
} else {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (DateTime.isDateTime(date)) {
|
|
28
|
+
return date.setZone(zone);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isDayjs(date)) {
|
|
32
|
+
return DateTime.fromISO(date.toISOString(), { zone });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (date instanceof Date) {
|
|
36
|
+
return DateTime.fromJSDate(date, { zone });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof date === 'string' && date) {
|
|
40
|
+
return DateTime.fromISO(date, { zone });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (typeof date === 'number') {
|
|
44
|
+
return DateTime.fromMillis(date, { zone });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw new Error(`Unsupported date format: ${date} (${date.constructor.name})`);
|
|
48
|
+
};
|
package/src/values.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type BasicValue = undefined | null | boolean | string | number | DateTime;
|
|
4
|
-
|
|
5
|
-
export type Value = any; // BasicValue | Symbol | Symbol[] | Record<string, Value> | Value[];
|
|
1
|
+
export type Value = unknown;
|
|
6
2
|
|
|
7
3
|
export type Values = {
|
|
8
4
|
name: string;
|
|
@@ -857,7 +857,7 @@ export type SomeQueryQuery = { manyObjects: Array<{ __typename: 'SomeObject', id
|
|
|
857
857
|
export type ReverseFiltersQueryQueryVariables = Exact<{ [key: string]: never; }>;
|
|
858
858
|
|
|
859
859
|
|
|
860
|
-
export type ReverseFiltersQueryQuery = { all: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, withFloat0: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, withFloat0_5: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, noneFloat0: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, noneFloat0_5: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }> };
|
|
860
|
+
export type ReverseFiltersQueryQuery = { all: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, withFloat0: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, withFloat0_5: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, noneFloat0: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, noneFloat0_5: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }>, noneFloat2: Array<{ __typename: 'AnotherObject', id: string, manyObjects: Array<{ __typename: 'SomeObject', float: number }> }> };
|
|
861
861
|
|
|
862
862
|
export type DeleteAnotherObjectMutationMutationVariables = Exact<{
|
|
863
863
|
id: Scalars['ID']['input'];
|
|
@@ -1061,6 +1061,8 @@ export namespace ReverseFiltersQuery {
|
|
|
1061
1061
|
export type ___manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat0']>)[number]>['manyObjects']>)[number]>;
|
|
1062
1062
|
export type noneFloat0_5 = NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat0_5']>)[number]>;
|
|
1063
1063
|
export type ____manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat0_5']>)[number]>['manyObjects']>)[number]>;
|
|
1064
|
+
export type noneFloat2 = NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat2']>)[number]>;
|
|
1065
|
+
export type _____manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat2']>)[number]>['manyObjects']>)[number]>;
|
|
1064
1066
|
}
|
|
1065
1067
|
|
|
1066
1068
|
export namespace DeleteAnotherObjectMutation {
|
|
@@ -35,7 +35,7 @@ export type AnotherObject = {
|
|
|
35
35
|
'name': string | null;
|
|
36
36
|
'myselfId': string | null;
|
|
37
37
|
'deleted': boolean;
|
|
38
|
-
'deletedAt': DateTime |
|
|
38
|
+
'deletedAt': DateTime | null;
|
|
39
39
|
'deletedById': string | null;
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -44,7 +44,7 @@ export type AnotherObjectInitializer = {
|
|
|
44
44
|
'name'?: string | null;
|
|
45
45
|
'myselfId'?: string | null;
|
|
46
46
|
'deleted'?: boolean;
|
|
47
|
-
'deletedAt'?: DateTime |
|
|
47
|
+
'deletedAt'?: DateTime | null;
|
|
48
48
|
'deletedById'?: string | null;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -53,7 +53,7 @@ export type AnotherObjectMutator = {
|
|
|
53
53
|
'name'?: string | null;
|
|
54
54
|
'myselfId'?: string | null;
|
|
55
55
|
'deleted'?: boolean;
|
|
56
|
-
'deletedAt'?: DateTime |
|
|
56
|
+
'deletedAt'?: DateTime | null;
|
|
57
57
|
'deletedById'?: string | null;
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -62,7 +62,7 @@ export type AnotherObjectSeed = {
|
|
|
62
62
|
'name'?: string | null;
|
|
63
63
|
'myselfId'?: string | null;
|
|
64
64
|
'deleted'?: boolean;
|
|
65
|
-
'deletedAt'?: DateTime |
|
|
65
|
+
'deletedAt'?: DateTime | null;
|
|
66
66
|
'deletedById'?: string | null;
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -73,12 +73,12 @@ export type SomeObject = {
|
|
|
73
73
|
'float': number;
|
|
74
74
|
'list': SomeEnum[];
|
|
75
75
|
'xyz': number;
|
|
76
|
-
'createdAt': DateTime
|
|
76
|
+
'createdAt': DateTime;
|
|
77
77
|
'createdById': string;
|
|
78
|
-
'updatedAt': DateTime
|
|
78
|
+
'updatedAt': DateTime;
|
|
79
79
|
'updatedById': string;
|
|
80
80
|
'deleted': boolean;
|
|
81
|
-
'deletedAt': DateTime |
|
|
81
|
+
'deletedAt': DateTime | null;
|
|
82
82
|
'deletedById': string | null;
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -89,12 +89,12 @@ export type SomeObjectInitializer = {
|
|
|
89
89
|
'float': number;
|
|
90
90
|
'list': SomeEnum[] | string;
|
|
91
91
|
'xyz': number;
|
|
92
|
-
'createdAt': DateTime
|
|
92
|
+
'createdAt': DateTime;
|
|
93
93
|
'createdById': string;
|
|
94
|
-
'updatedAt': DateTime
|
|
94
|
+
'updatedAt': DateTime;
|
|
95
95
|
'updatedById': string;
|
|
96
96
|
'deleted'?: boolean;
|
|
97
|
-
'deletedAt'?: DateTime |
|
|
97
|
+
'deletedAt'?: DateTime | null;
|
|
98
98
|
'deletedById'?: string | null;
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -105,12 +105,12 @@ export type SomeObjectMutator = {
|
|
|
105
105
|
'float'?: number;
|
|
106
106
|
'list'?: SomeEnum[] | string;
|
|
107
107
|
'xyz'?: number;
|
|
108
|
-
'createdAt'?: DateTime
|
|
108
|
+
'createdAt'?: DateTime;
|
|
109
109
|
'createdById'?: string;
|
|
110
|
-
'updatedAt'?: DateTime
|
|
110
|
+
'updatedAt'?: DateTime;
|
|
111
111
|
'updatedById'?: string;
|
|
112
112
|
'deleted'?: boolean;
|
|
113
|
-
'deletedAt'?: DateTime |
|
|
113
|
+
'deletedAt'?: DateTime | null;
|
|
114
114
|
'deletedById'?: string | null;
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -121,12 +121,12 @@ export type SomeObjectSeed = {
|
|
|
121
121
|
'float': number;
|
|
122
122
|
'list': string[] | string;
|
|
123
123
|
'xyz': number;
|
|
124
|
-
'createdAt'?: DateTime
|
|
124
|
+
'createdAt'?: DateTime;
|
|
125
125
|
'createdById'?: string;
|
|
126
|
-
'updatedAt'?: DateTime
|
|
126
|
+
'updatedAt'?: DateTime;
|
|
127
127
|
'updatedById'?: string;
|
|
128
128
|
'deleted'?: boolean;
|
|
129
|
-
'deletedAt'?: DateTime |
|
|
129
|
+
'deletedAt'?: DateTime | null;
|
|
130
130
|
'deletedById'?: string | null;
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -135,12 +135,12 @@ export type Reaction = {
|
|
|
135
135
|
'type': ReactionType;
|
|
136
136
|
'parentId': string | null;
|
|
137
137
|
'content': string | null;
|
|
138
|
-
'createdAt': DateTime
|
|
138
|
+
'createdAt': DateTime;
|
|
139
139
|
'createdById': string;
|
|
140
|
-
'updatedAt': DateTime
|
|
140
|
+
'updatedAt': DateTime;
|
|
141
141
|
'updatedById': string;
|
|
142
142
|
'deleted': boolean;
|
|
143
|
-
'deletedAt': DateTime |
|
|
143
|
+
'deletedAt': DateTime | null;
|
|
144
144
|
'deletedById': string | null;
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -149,12 +149,12 @@ export type ReactionInitializer = {
|
|
|
149
149
|
'type': ReactionType;
|
|
150
150
|
'parentId'?: string | null;
|
|
151
151
|
'content'?: string | null;
|
|
152
|
-
'createdAt': DateTime
|
|
152
|
+
'createdAt': DateTime;
|
|
153
153
|
'createdById': string;
|
|
154
|
-
'updatedAt': DateTime
|
|
154
|
+
'updatedAt': DateTime;
|
|
155
155
|
'updatedById': string;
|
|
156
156
|
'deleted'?: boolean;
|
|
157
|
-
'deletedAt'?: DateTime |
|
|
157
|
+
'deletedAt'?: DateTime | null;
|
|
158
158
|
'deletedById'?: string | null;
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -163,12 +163,12 @@ export type ReactionMutator = {
|
|
|
163
163
|
'type'?: ReactionType;
|
|
164
164
|
'parentId'?: string | null;
|
|
165
165
|
'content'?: string | null;
|
|
166
|
-
'createdAt'?: DateTime
|
|
166
|
+
'createdAt'?: DateTime;
|
|
167
167
|
'createdById'?: string;
|
|
168
|
-
'updatedAt'?: DateTime
|
|
168
|
+
'updatedAt'?: DateTime;
|
|
169
169
|
'updatedById'?: string;
|
|
170
170
|
'deleted'?: boolean;
|
|
171
|
-
'deletedAt'?: DateTime |
|
|
171
|
+
'deletedAt'?: DateTime | null;
|
|
172
172
|
'deletedById'?: string | null;
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -177,12 +177,12 @@ export type Review = {
|
|
|
177
177
|
'type': ReactionType;
|
|
178
178
|
'parentId': string | null;
|
|
179
179
|
'content': string | null;
|
|
180
|
-
'createdAt': DateTime
|
|
180
|
+
'createdAt': DateTime;
|
|
181
181
|
'createdById': string;
|
|
182
|
-
'updatedAt': DateTime
|
|
182
|
+
'updatedAt': DateTime;
|
|
183
183
|
'updatedById': string;
|
|
184
184
|
'deleted': boolean;
|
|
185
|
-
'deletedAt': DateTime |
|
|
185
|
+
'deletedAt': DateTime | null;
|
|
186
186
|
'deletedById': string | null;
|
|
187
187
|
'rating': number | null;
|
|
188
188
|
}
|
|
@@ -201,12 +201,12 @@ export type ReviewSeed = {
|
|
|
201
201
|
'id': string;
|
|
202
202
|
'parentId'?: string | null;
|
|
203
203
|
'content'?: string | null;
|
|
204
|
-
'createdAt'?: DateTime
|
|
204
|
+
'createdAt'?: DateTime;
|
|
205
205
|
'createdById'?: string;
|
|
206
|
-
'updatedAt'?: DateTime
|
|
206
|
+
'updatedAt'?: DateTime;
|
|
207
207
|
'updatedById'?: string;
|
|
208
208
|
'deleted'?: boolean;
|
|
209
|
-
'deletedAt'?: DateTime |
|
|
209
|
+
'deletedAt'?: DateTime | null;
|
|
210
210
|
'deletedById'?: string | null;
|
|
211
211
|
'rating'?: number | null;
|
|
212
212
|
}
|
|
@@ -216,12 +216,12 @@ export type Question = {
|
|
|
216
216
|
'type': ReactionType;
|
|
217
217
|
'parentId': string | null;
|
|
218
218
|
'content': string | null;
|
|
219
|
-
'createdAt': DateTime
|
|
219
|
+
'createdAt': DateTime;
|
|
220
220
|
'createdById': string;
|
|
221
|
-
'updatedAt': DateTime
|
|
221
|
+
'updatedAt': DateTime;
|
|
222
222
|
'updatedById': string;
|
|
223
223
|
'deleted': boolean;
|
|
224
|
-
'deletedAt': DateTime |
|
|
224
|
+
'deletedAt': DateTime | null;
|
|
225
225
|
'deletedById': string | null;
|
|
226
226
|
}
|
|
227
227
|
|
|
@@ -237,12 +237,12 @@ export type QuestionSeed = {
|
|
|
237
237
|
'id': string;
|
|
238
238
|
'parentId'?: string | null;
|
|
239
239
|
'content'?: string | null;
|
|
240
|
-
'createdAt'?: DateTime
|
|
240
|
+
'createdAt'?: DateTime;
|
|
241
241
|
'createdById'?: string;
|
|
242
|
-
'updatedAt'?: DateTime
|
|
242
|
+
'updatedAt'?: DateTime;
|
|
243
243
|
'updatedById'?: string;
|
|
244
244
|
'deleted'?: boolean;
|
|
245
|
-
'deletedAt'?: DateTime |
|
|
245
|
+
'deletedAt'?: DateTime | null;
|
|
246
246
|
'deletedById'?: string | null;
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -251,12 +251,12 @@ export type Answer = {
|
|
|
251
251
|
'type': ReactionType;
|
|
252
252
|
'parentId': string | null;
|
|
253
253
|
'content': string | null;
|
|
254
|
-
'createdAt': DateTime
|
|
254
|
+
'createdAt': DateTime;
|
|
255
255
|
'createdById': string;
|
|
256
|
-
'updatedAt': DateTime
|
|
256
|
+
'updatedAt': DateTime;
|
|
257
257
|
'updatedById': string;
|
|
258
258
|
'deleted': boolean;
|
|
259
|
-
'deletedAt': DateTime |
|
|
259
|
+
'deletedAt': DateTime | null;
|
|
260
260
|
'deletedById': string | null;
|
|
261
261
|
}
|
|
262
262
|
|
|
@@ -272,12 +272,12 @@ export type AnswerSeed = {
|
|
|
272
272
|
'id': string;
|
|
273
273
|
'parentId'?: string | null;
|
|
274
274
|
'content'?: string | null;
|
|
275
|
-
'createdAt'?: DateTime
|
|
275
|
+
'createdAt'?: DateTime;
|
|
276
276
|
'createdById'?: string;
|
|
277
|
-
'updatedAt'?: DateTime
|
|
277
|
+
'updatedAt'?: DateTime;
|
|
278
278
|
'updatedById'?: string;
|
|
279
279
|
'deleted'?: boolean;
|
|
280
|
-
'deletedAt'?: DateTime |
|
|
280
|
+
'deletedAt'?: DateTime | null;
|
|
281
281
|
'deletedById'?: string | null;
|
|
282
282
|
}
|
|
283
283
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Knex } from 'knex';
|
|
2
2
|
import { pick } from 'lodash';
|
|
3
|
-
import { DateTime } from 'luxon';
|
|
4
3
|
import { getColumnName, isInTable, modelNeedsTable } from '../../../src';
|
|
5
4
|
import { SeedData } from '../../generated/db';
|
|
6
5
|
import { models } from '../models';
|
|
@@ -78,19 +77,18 @@ export const seed: SeedData = {
|
|
|
78
77
|
],
|
|
79
78
|
};
|
|
80
79
|
|
|
81
|
-
export const setupSeed = async (knex: Knex) => {
|
|
82
|
-
const now = DateTime.now();
|
|
80
|
+
export const setupSeed = async (knex: Knex, now: string) => {
|
|
83
81
|
for (const [table, entities] of Object.entries(seed)) {
|
|
84
82
|
const model = models.getModel(table, 'entity');
|
|
85
83
|
const mappedEntities = entities.map((entity, i) => ({
|
|
86
84
|
...entity,
|
|
87
85
|
...(model.parent && { type: model.name }),
|
|
88
86
|
...(model.creatable && {
|
|
89
|
-
createdAt: now
|
|
87
|
+
createdAt: addSeconds(now, i),
|
|
90
88
|
createdById: ADMIN_ID,
|
|
91
89
|
}),
|
|
92
90
|
...(model.updatable && {
|
|
93
|
-
updatedAt: now
|
|
91
|
+
updatedAt: addSeconds(now, i),
|
|
94
92
|
updatedById: ADMIN_ID,
|
|
95
93
|
}),
|
|
96
94
|
}));
|
|
@@ -112,3 +110,9 @@ export const setupSeed = async (knex: Knex) => {
|
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
};
|
|
113
|
+
|
|
114
|
+
const addSeconds = (dateString: string, seconds: number) => {
|
|
115
|
+
const date = new Date(dateString);
|
|
116
|
+
date.setSeconds(date.getSeconds() + seconds);
|
|
117
|
+
return date.toISOString();
|
|
118
|
+
};
|
package/tests/utils/server.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { TypedQueryDocumentNode } from 'graphql';
|
|
|
2
2
|
import graphqlRequest, { RequestDocument, Variables } from 'graphql-request';
|
|
3
3
|
import { RequestListener, createServer } from 'http';
|
|
4
4
|
import { Knex } from 'knex';
|
|
5
|
-
import { DateTime } from 'luxon';
|
|
6
5
|
import { up } from '../../migrations/20230912185644_setup';
|
|
7
6
|
import { execute } from '../../src';
|
|
8
7
|
import { getKnex } from './database/knex';
|
|
@@ -44,7 +43,8 @@ export const withServer = async (
|
|
|
44
43
|
|
|
45
44
|
try {
|
|
46
45
|
await up(knex);
|
|
47
|
-
|
|
46
|
+
const now = '2020-01-01T00:00:00.000Z';
|
|
47
|
+
await setupSeed(knex, now);
|
|
48
48
|
|
|
49
49
|
handler = async (req, res) => {
|
|
50
50
|
const user = await knex('User').where({ id: ADMIN_ID }).first();
|
|
@@ -66,7 +66,7 @@ export const withServer = async (
|
|
|
66
66
|
user,
|
|
67
67
|
models,
|
|
68
68
|
permissions,
|
|
69
|
-
now
|
|
69
|
+
now,
|
|
70
70
|
body,
|
|
71
71
|
});
|
|
72
72
|
|