@smartive/graphql-magic 8.0.0 → 8.1.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.
@@ -13,6 +13,10 @@ export type RawModel = {
13
13
  | { kind: 'enum'; values: string[]; deleted?: true }
14
14
  | { kind: 'raw-enum'; values: string[] }
15
15
  | { kind: 'interface'; fields: ModelField[] }
16
+ | {
17
+ kind: 'input';
18
+ fields: ObjectField[];
19
+ }
16
20
  | {
17
21
  kind: 'object';
18
22
  fields: ObjectField[];
@@ -42,6 +46,7 @@ export type EnumModel = Extract<RawModel, { kind: 'enum' }>;
42
46
  export type RawEnumModel = Extract<RawModel, { kind: 'raw-enum' }>;
43
47
  export type InterfaceModel = Extract<RawModel, { kind: 'interface' }>;
44
48
  export type ObjectModel = Extract<RawModel, { kind: 'object' }>;
49
+ export type InputModel = Extract<RawModel, { kind: 'input' }>;
45
50
  export type EntityModel = Extract<RawModel, { kind: 'entity' }>;
46
51
 
47
52
  type BaseNumberType = {
@@ -11,6 +11,7 @@ import {
11
11
  EntityModel,
12
12
  EnumField,
13
13
  EnumModel,
14
+ InputModel,
14
15
  Model,
15
16
  ModelField,
16
17
  Models,
@@ -55,6 +56,8 @@ export const isScalarModel = (model: RawModel): model is ScalarModel => model.ki
55
56
 
56
57
  export const isObjectModel = (model: RawModel): model is ObjectModel => model.kind === 'object';
57
58
 
59
+ export const isInputModel = (model: RawModel): model is InputModel => model.kind === 'input';
60
+
58
61
  export const isEnumList = (models: RawModels, field: ModelField) =>
59
62
  field?.list === true && models.find(({ name }) => name === field.kind)?.kind === 'enum';
60
63
 
@@ -5,6 +5,7 @@ import {
5
5
  getModelPluralField,
6
6
  getModels,
7
7
  isEnumModel,
8
+ isInputModel,
8
9
  isObjectModel,
9
10
  isQueriableField,
10
11
  isRawEnumModel,
@@ -26,7 +27,11 @@ export const generateDefinitions = (rawModels: RawModels): DefinitionNode[] => {
26
27
  ...rawModels.filter(isEnumModel).map((model) => enm(model.name, model.values)),
27
28
  ...rawModels.filter(isRawEnumModel).map((model) => enm(model.name, model.values)),
28
29
  ...rawModels.filter(isScalarModel).map((model) => scalar(model.name)),
29
- ...rawModels.filter(isObjectModel).map((model) => object(model.name, model.fields)),
30
+ ...rawModels
31
+ .filter(isObjectModel)
32
+ .filter(({ name }) => !['Query', 'Mutation'].includes(name))
33
+ .map((model) => object(model.name, model.fields)),
34
+ ...rawModels.filter(isInputModel).map((model) => input(model.name, model.fields)),
30
35
  ...rawModels
31
36
  .filter(isObjectModel)
32
37
  .filter((model) =>
@@ -188,6 +193,10 @@ export const generateDefinitions = (rawModels: RawModels): DefinitionNode[] => {
188
193
  { name: 'offset', type: 'Int' },
189
194
  ],
190
195
  })),
196
+ ...rawModels
197
+ .filter(isObjectModel)
198
+ .filter((model) => model.name === 'Query')
199
+ .flatMap((model) => model.fields),
191
200
  ]),
192
201
 
193
202
  object('Mutation', [
@@ -264,6 +273,10 @@ export const generateDefinitions = (rawModels: RawModels): DefinitionNode[] => {
264
273
  return mutations;
265
274
  })
266
275
  ),
276
+ ...rawModels
277
+ .filter(isObjectModel)
278
+ .filter((model) => model.name === 'Mutation')
279
+ .flatMap((model) => model.fields),
267
280
  ]),
268
281
  ];
269
282
  };
@@ -1,22 +1,11 @@
1
1
  import { writeFileSync } from 'fs';
2
2
  import { simpleGit } from 'simple-git';
3
- import { MigrationGenerator } from '../../src/migrations/generate';
3
+ import { MigrationGenerator, getMigrationDate } from '../../src/migrations/generate';
4
4
  import { getKnex } from './database/knex';
5
5
  import { rawModels } from './models';
6
6
 
7
7
  const git = simpleGit();
8
8
 
9
- const getDate = () => {
10
- const date = new Date();
11
- const year = date.getFullYear();
12
- const month = String(date.getMonth() + 1).padStart(2, '0');
13
- const day = String(date.getDate()).padStart(2, '0');
14
- const hours = String(date.getHours()).padStart(2, '0');
15
- const minutes = String(date.getMinutes()).padStart(2, '0');
16
- const seconds = String(date.getSeconds()).padStart(2, '0');
17
-
18
- return `${year}${month}${day}${hours}${minutes}${seconds}`;
19
- };
20
9
 
21
10
  const writeMigration = async () => {
22
11
  const name = process.argv[2] || (await git.branch()).current.split('/').pop();
@@ -26,7 +15,7 @@ const writeMigration = async () => {
26
15
  try {
27
16
  const migrations = await new MigrationGenerator(knex, rawModels).generate();
28
17
 
29
- writeFileSync(`tmp/${getDate()}_${name}.ts`, migrations);
18
+ writeFileSync(`tmp/${getMigrationDate()}_${name}.ts`, migrations);
30
19
  } finally {
31
20
  await knex.destroy();
32
21
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", "dist"],
4
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "include": ["./src/**/*.ts", "./src/**/*.tsx"],
3
- "exclude": ["node_modules", "dist"],
3
+ "exclude": ["node_modules", "dist", "src/bin"],
4
4
  "compilerOptions": {
5
5
  "outDir": "./dist/esm",
6
6
  "rootDir": "./src",