@smartive/graphql-magic 16.3.7 → 16.3.8

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/dist/bin/gqm.cjs +37 -35
  3. package/dist/cjs/index.cjs +51 -48
  4. package/dist/esm/api/execute.d.ts +1 -5
  5. package/dist/esm/api/execute.js.map +1 -1
  6. package/dist/esm/client/queries.d.ts +4 -4
  7. package/dist/esm/client/queries.js.map +1 -1
  8. package/dist/esm/db/generate.js +2 -0
  9. package/dist/esm/db/generate.js.map +1 -1
  10. package/dist/esm/migrations/generate.js +1 -1
  11. package/dist/esm/migrations/generate.js.map +1 -1
  12. package/dist/esm/models/models.d.ts +1 -1
  13. package/dist/esm/models/models.js.map +1 -1
  14. package/dist/esm/models/utils.d.ts +8 -12
  15. package/dist/esm/models/utils.js +3 -5
  16. package/dist/esm/models/utils.js.map +1 -1
  17. package/dist/esm/permissions/check.js +0 -15
  18. package/dist/esm/permissions/check.js.map +1 -1
  19. package/dist/esm/permissions/generate.d.ts +5 -19
  20. package/dist/esm/permissions/generate.js.map +1 -1
  21. package/dist/esm/resolvers/arguments.js.map +1 -1
  22. package/dist/esm/resolvers/filters.js +0 -2
  23. package/dist/esm/resolvers/filters.js.map +1 -1
  24. package/dist/esm/resolvers/mutations.js +5 -4
  25. package/dist/esm/resolvers/mutations.js.map +1 -1
  26. package/dist/esm/resolvers/node.js.map +1 -1
  27. package/dist/esm/resolvers/resolver.d.ts +2 -2
  28. package/dist/esm/resolvers/resolver.js +1 -1
  29. package/dist/esm/resolvers/resolver.js.map +1 -1
  30. package/dist/esm/resolvers/selects.js.map +1 -1
  31. package/dist/esm/resolvers/utils.d.ts +2 -6
  32. package/dist/esm/resolvers/utils.js +4 -2
  33. package/dist/esm/resolvers/utils.js.map +1 -1
  34. package/dist/esm/schema/utils.d.ts +4 -4
  35. package/dist/esm/schema/utils.js +31 -30
  36. package/dist/esm/schema/utils.js.map +1 -1
  37. package/dist/esm/utils/dates.d.ts +2 -4
  38. package/dist/esm/utils/dates.js +1 -3
  39. package/dist/esm/utils/dates.js.map +1 -1
  40. package/docs/docs/1-tutorial.md +1 -1
  41. package/eslint.config.mjs +42 -0
  42. package/migrations/20230912185644_setup.ts +1 -1
  43. package/package.json +6 -11
  44. package/src/api/execute.ts +1 -0
  45. package/src/bin/gqm/codegen.ts +1 -1
  46. package/src/client/gql.ts +1 -1
  47. package/src/client/mutations.ts +8 -8
  48. package/src/client/queries.ts +15 -14
  49. package/src/db/generate.ts +8 -5
  50. package/src/migrations/generate.ts +26 -22
  51. package/src/models/models.ts +24 -9
  52. package/src/models/mutation-hook.ts +1 -1
  53. package/src/models/utils.ts +8 -7
  54. package/src/permissions/check.ts +22 -30
  55. package/src/permissions/generate.ts +8 -25
  56. package/src/resolvers/arguments.ts +7 -2
  57. package/src/resolvers/filters.ts +8 -10
  58. package/src/resolvers/mutations.ts +19 -16
  59. package/src/resolvers/node.ts +3 -2
  60. package/src/resolvers/resolver.ts +11 -10
  61. package/src/resolvers/selects.ts +4 -3
  62. package/src/resolvers/utils.ts +15 -10
  63. package/src/schema/generate.ts +11 -11
  64. package/src/schema/utils.ts +84 -82
  65. package/src/utils/dates.ts +3 -3
  66. package/tests/generated/api/index.ts +2 -2
  67. package/tests/generated/client/index.ts +1 -193
  68. package/tests/generated/db/index.ts +4 -4
  69. package/tests/generated/models.json +2 -1
  70. package/tests/generated/schema.graphql +1 -1
  71. package/tests/utils/graphql-client.ts +49 -0
  72. package/tests/utils/models.ts +1 -0
  73. package/tests/utils/server.ts +4 -5
  74. package/tsconfig.eslint.json +18 -3
  75. package/tsconfig.json +3 -1
  76. package/.eslintrc +0 -13
@@ -675,7 +675,7 @@ export type User = {
675
675
  deletedReactions: Array<Reaction>;
676
676
  deletedReviews: Array<Review>;
677
677
  id: Scalars['ID']['output'];
678
- role: Maybe<Role>;
678
+ role: Role;
679
679
  updatedAnswers: Array<Answer>;
680
680
  updatedManyObjects: Array<SomeObject>;
681
681
  updatedQuestions: Array<Question>;
@@ -1025,195 +1025,3 @@ export type RestoreAnswerMutationMutationVariables = Exact<{
1025
1025
 
1026
1026
 
1027
1027
  export type RestoreAnswerMutationMutation = { restoreAnswer: string };
1028
-
1029
- type DiscriminateUnion<T, U> = T extends U ? T : never;
1030
-
1031
- export namespace DeleteAnotherObject {
1032
- export type Variables = DeleteAnotherObjectMutationVariables;
1033
- export type mutation = DeleteAnotherObjectMutation;
1034
- }
1035
-
1036
- export namespace GetAnotherObject {
1037
- export type Variables = GetAnotherObjectQueryVariables;
1038
- export type query = GetAnotherObjectQuery;
1039
- export type anotherObjects = NonNullable<(NonNullable<GetAnotherObjectQuery['anotherObjects']>)[number]>;
1040
- }
1041
-
1042
- export namespace GetReactions {
1043
- export type Variables = GetReactionsQueryVariables;
1044
- export type query = GetReactionsQuery;
1045
- export type reactions = NonNullable<(NonNullable<GetReactionsQuery['reactions']>)[number]>;
1046
- export type ReviewInlineFragment = (DiscriminateUnion<NonNullable<(NonNullable<GetReactionsQuery['reactions']>)[number]>, { __typename: 'Review' }>);
1047
- }
1048
-
1049
- export namespace GetReaction {
1050
- export type Variables = GetReactionQueryVariables;
1051
- export type query = GetReactionQuery;
1052
- export type reaction = (NonNullable<GetReactionQuery['reaction']>);
1053
- export type ReviewInlineFragment = (DiscriminateUnion<(NonNullable<GetReactionQuery['reaction']>), { __typename: 'Review' }>);
1054
- }
1055
-
1056
- export namespace GetReviews {
1057
- export type Variables = GetReviewsQueryVariables;
1058
- export type query = GetReviewsQuery;
1059
- export type reviews = NonNullable<(NonNullable<GetReviewsQuery['reviews']>)[number]>;
1060
- }
1061
-
1062
- export namespace GetReview {
1063
- export type Variables = GetReviewQueryVariables;
1064
- export type query = GetReviewQuery;
1065
- export type review = (NonNullable<GetReviewQuery['review']>);
1066
- }
1067
-
1068
- export namespace CreateReview {
1069
- export type Variables = CreateReviewMutationVariables;
1070
- export type mutation = CreateReviewMutation;
1071
- export type createReview = (NonNullable<CreateReviewMutation['createReview']>);
1072
- }
1073
-
1074
- export namespace UpdateReview {
1075
- export type Variables = UpdateReviewMutationVariables;
1076
- export type mutation = UpdateReviewMutation;
1077
- export type updateReview = (NonNullable<UpdateReviewMutation['updateReview']>);
1078
- }
1079
-
1080
- export namespace SomeQuery {
1081
- export type Variables = SomeQueryQueryVariables;
1082
- export type query = SomeQueryQuery;
1083
- export type manyObjects = NonNullable<(NonNullable<SomeQueryQuery['manyObjects']>)[number]>;
1084
- export type another = (NonNullable<NonNullable<(NonNullable<SomeQueryQuery['manyObjects']>)[number]>['another']>);
1085
- export type _manyObjects = NonNullable<(NonNullable<(NonNullable<NonNullable<(NonNullable<SomeQueryQuery['manyObjects']>)[number]>['another']>)['manyObjects']>)[number]>;
1086
- }
1087
-
1088
- export namespace ReverseFiltersQuery {
1089
- export type Variables = ReverseFiltersQueryQueryVariables;
1090
- export type query = ReverseFiltersQueryQuery;
1091
- export type all = NonNullable<(NonNullable<ReverseFiltersQueryQuery['all']>)[number]>;
1092
- export type manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['all']>)[number]>['manyObjects']>)[number]>;
1093
- export type withFloat0 = NonNullable<(NonNullable<ReverseFiltersQueryQuery['withFloat0']>)[number]>;
1094
- export type _manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['withFloat0']>)[number]>['manyObjects']>)[number]>;
1095
- export type withFloat0_5 = NonNullable<(NonNullable<ReverseFiltersQueryQuery['withFloat0_5']>)[number]>;
1096
- export type __manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['withFloat0_5']>)[number]>['manyObjects']>)[number]>;
1097
- export type noneFloat0 = NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat0']>)[number]>;
1098
- export type ___manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat0']>)[number]>['manyObjects']>)[number]>;
1099
- export type noneFloat0_5 = NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat0_5']>)[number]>;
1100
- export type ____manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat0_5']>)[number]>['manyObjects']>)[number]>;
1101
- export type noneFloat2 = NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat2']>)[number]>;
1102
- export type _____manyObjects = NonNullable<(NonNullable<NonNullable<(NonNullable<ReverseFiltersQueryQuery['noneFloat2']>)[number]>['manyObjects']>)[number]>;
1103
- }
1104
-
1105
- export namespace NotQuery {
1106
- export type Variables = NotQueryQueryVariables;
1107
- export type query = NotQueryQuery;
1108
- export type manyObjects = NonNullable<(NonNullable<NotQueryQuery['manyObjects']>)[number]>;
1109
- }
1110
-
1111
- export namespace AndQuery {
1112
- export type Variables = AndQueryQueryVariables;
1113
- export type query = AndQueryQuery;
1114
- export type manyObjects = NonNullable<(NonNullable<AndQueryQuery['manyObjects']>)[number]>;
1115
- }
1116
-
1117
- export namespace OrQuery {
1118
- export type Variables = OrQueryQueryVariables;
1119
- export type query = OrQueryQuery;
1120
- export type manyObjects = NonNullable<(NonNullable<OrQueryQuery['manyObjects']>)[number]>;
1121
- }
1122
-
1123
- export namespace DeleteAnotherObjectMutation {
1124
- export type Variables = DeleteAnotherObjectMutationMutationVariables;
1125
- export type mutation = DeleteAnotherObjectMutationMutation;
1126
- }
1127
-
1128
- export namespace RestoreAnotherObjectMutation {
1129
- export type Variables = RestoreAnotherObjectMutationMutationVariables;
1130
- export type mutation = RestoreAnotherObjectMutationMutation;
1131
- }
1132
-
1133
- export namespace CreateSomeObjectMutation {
1134
- export type Variables = CreateSomeObjectMutationMutationVariables;
1135
- export type mutation = CreateSomeObjectMutationMutation;
1136
- export type createSomeObject = (NonNullable<CreateSomeObjectMutationMutation['createSomeObject']>);
1137
- }
1138
-
1139
- export namespace UpdateSomeObjectMutation {
1140
- export type Variables = UpdateSomeObjectMutationMutationVariables;
1141
- export type mutation = UpdateSomeObjectMutationMutation;
1142
- export type updateSomeObject = (NonNullable<UpdateSomeObjectMutationMutation['updateSomeObject']>);
1143
- }
1144
-
1145
- export namespace DeleteSomeObjectMutation {
1146
- export type Variables = DeleteSomeObjectMutationMutationVariables;
1147
- export type mutation = DeleteSomeObjectMutationMutation;
1148
- }
1149
-
1150
- export namespace RestoreSomeObjectMutation {
1151
- export type Variables = RestoreSomeObjectMutationMutationVariables;
1152
- export type mutation = RestoreSomeObjectMutationMutation;
1153
- }
1154
-
1155
- export namespace CreateReviewMutation {
1156
- export type Variables = CreateReviewMutationMutationVariables;
1157
- export type mutation = CreateReviewMutationMutation;
1158
- export type createReview = (NonNullable<CreateReviewMutationMutation['createReview']>);
1159
- }
1160
-
1161
- export namespace UpdateReviewMutation {
1162
- export type Variables = UpdateReviewMutationMutationVariables;
1163
- export type mutation = UpdateReviewMutationMutation;
1164
- export type updateReview = (NonNullable<UpdateReviewMutationMutation['updateReview']>);
1165
- }
1166
-
1167
- export namespace DeleteReviewMutation {
1168
- export type Variables = DeleteReviewMutationMutationVariables;
1169
- export type mutation = DeleteReviewMutationMutation;
1170
- }
1171
-
1172
- export namespace RestoreReviewMutation {
1173
- export type Variables = RestoreReviewMutationMutationVariables;
1174
- export type mutation = RestoreReviewMutationMutation;
1175
- }
1176
-
1177
- export namespace CreateQuestionMutation {
1178
- export type Variables = CreateQuestionMutationMutationVariables;
1179
- export type mutation = CreateQuestionMutationMutation;
1180
- export type createQuestion = (NonNullable<CreateQuestionMutationMutation['createQuestion']>);
1181
- }
1182
-
1183
- export namespace UpdateQuestionMutation {
1184
- export type Variables = UpdateQuestionMutationMutationVariables;
1185
- export type mutation = UpdateQuestionMutationMutation;
1186
- export type updateQuestion = (NonNullable<UpdateQuestionMutationMutation['updateQuestion']>);
1187
- }
1188
-
1189
- export namespace DeleteQuestionMutation {
1190
- export type Variables = DeleteQuestionMutationMutationVariables;
1191
- export type mutation = DeleteQuestionMutationMutation;
1192
- }
1193
-
1194
- export namespace RestoreQuestionMutation {
1195
- export type Variables = RestoreQuestionMutationMutationVariables;
1196
- export type mutation = RestoreQuestionMutationMutation;
1197
- }
1198
-
1199
- export namespace CreateAnswerMutation {
1200
- export type Variables = CreateAnswerMutationMutationVariables;
1201
- export type mutation = CreateAnswerMutationMutation;
1202
- export type createAnswer = (NonNullable<CreateAnswerMutationMutation['createAnswer']>);
1203
- }
1204
-
1205
- export namespace UpdateAnswerMutation {
1206
- export type Variables = UpdateAnswerMutationMutationVariables;
1207
- export type mutation = UpdateAnswerMutationMutation;
1208
- export type updateAnswer = (NonNullable<UpdateAnswerMutationMutation['updateAnswer']>);
1209
- }
1210
-
1211
- export namespace DeleteAnswerMutation {
1212
- export type Variables = DeleteAnswerMutationMutationVariables;
1213
- export type mutation = DeleteAnswerMutationMutation;
1214
- }
1215
-
1216
- export namespace RestoreAnswerMutation {
1217
- export type Variables = RestoreAnswerMutationMutationVariables;
1218
- export type mutation = RestoreAnswerMutationMutation;
1219
- }
@@ -9,25 +9,25 @@ export type ReactionType = 'Review' | 'Question' | 'Answer';
9
9
  export type User = {
10
10
  'id': string;
11
11
  'username': string | null;
12
- 'role': Role | null;
12
+ 'role': Role;
13
13
  }
14
14
 
15
15
  export type UserInitializer = {
16
16
  'id': string;
17
17
  'username'?: string | null;
18
- 'role'?: Role | null;
18
+ 'role': Role;
19
19
  }
20
20
 
21
21
  export type UserMutator = {
22
22
  'id'?: string;
23
23
  'username'?: string | null;
24
- 'role'?: Role | null;
24
+ 'role'?: Role;
25
25
  }
26
26
 
27
27
  export type UserSeed = {
28
28
  'id': string;
29
29
  'username'?: string | null;
30
- 'role'?: string | null;
30
+ 'role': string;
31
31
  }
32
32
 
33
33
  export type AnotherObject = {
@@ -45,7 +45,8 @@
45
45
  {
46
46
  "name": "role",
47
47
  "kind": "enum",
48
- "type": "Role"
48
+ "type": "Role",
49
+ "nonNull": true
49
50
  }
50
51
  ]
51
52
  },
@@ -319,7 +319,7 @@ scalar Upload
319
319
  type User {
320
320
  id: ID!
321
321
  username: String
322
- role: Role
322
+ role: Role!
323
323
  deletedAnotherObjects(where: AnotherObjectWhere, orderBy: [AnotherObjectOrderBy!], limit: Int, offset: Int): [AnotherObject!]!
324
324
  createdManyObjects(where: SomeObjectWhere, search: String, orderBy: [SomeObjectOrderBy!], limit: Int, offset: Int): [SomeObject!]!
325
325
  updatedManyObjects(where: SomeObjectWhere, search: String, orderBy: [SomeObjectOrderBy!], limit: Int, offset: Int): [SomeObject!]!
@@ -0,0 +1,49 @@
1
+ type Variables = Record<string, unknown>;
2
+
3
+ interface GraphQLResponse<T = any> {
4
+ data?: T;
5
+ errors?: {
6
+ message: string;
7
+ locations?: { line: number; column: number }[];
8
+ path?: string[];
9
+ extensions?: Record<string, unknown>;
10
+ }[];
11
+ }
12
+
13
+ /**
14
+ * Simple GraphQL client using native fetch
15
+ */
16
+ export const graphqlRequest = async <T = any>(
17
+ url: string,
18
+ query: string,
19
+ variables?: Variables,
20
+ headers?: HeadersInit,
21
+ ): Promise<T> => {
22
+ const response = await fetch(url, {
23
+ method: 'POST',
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ ...headers,
27
+ },
28
+ body: JSON.stringify({
29
+ query,
30
+ variables,
31
+ }),
32
+ });
33
+
34
+ if (!response.ok) {
35
+ throw new Error(`HTTP error! Status: ${response.status}.`);
36
+ }
37
+
38
+ const result = (await response.json()) as GraphQLResponse<T>;
39
+
40
+ if (result.errors?.length) {
41
+ throw new Error(`GraphQL Error: ${result.errors.map((e) => e.message).join(', ')}.`);
42
+ }
43
+
44
+ if (!result.data) {
45
+ throw new Error('No data returned from GraphQL request.');
46
+ }
47
+
48
+ return result.data;
49
+ };
@@ -31,6 +31,7 @@ const modelDefinitions: ModelDefinitions = [
31
31
  name: 'role',
32
32
  kind: 'enum',
33
33
  type: 'Role',
34
+ nonNull: true,
34
35
  },
35
36
  ],
36
37
  },
@@ -1,16 +1,15 @@
1
- import { TypedQueryDocumentNode } from 'graphql';
2
- import graphqlRequest, { RequestDocument, Variables } from 'graphql-request';
3
1
  import { RequestListener, createServer } from 'http';
4
2
  import { Knex } from 'knex';
5
3
  import { up } from '../../migrations/20230912185644_setup';
6
4
  import { execute } from '../../src';
7
5
  import { getKnex } from './database/knex';
8
6
  import { ADMIN_ID, setupSeed } from './database/seed';
7
+ import { graphqlRequest } from './graphql-client';
9
8
  import { models, permissions } from './models';
10
9
 
11
10
  export const withServer = async (
12
11
  cb: (
13
- request: (document: RequestDocument | TypedQueryDocumentNode, ...variablesAndRequestHeaders: any) => Promise<any>,
12
+ request: (document: string, ...variablesAndRequestHeaders: any) => Promise<any>,
14
13
  knex: Knex
15
14
  ) => Promise<void>
16
15
  ) => {
@@ -66,8 +65,8 @@ export const withServer = async (
66
65
  res.end(JSON.stringify(result));
67
66
  };
68
67
 
69
- const request = <T, V extends Variables = Variables>(
70
- document: RequestDocument | TypedQueryDocumentNode<T, V>,
68
+ const request = <T, V>(
69
+ document: string,
71
70
  ...variablesAndRequestHeaders: any
72
71
  ) => graphqlRequest(`http://localhost:${port}`, document, ...variablesAndRequestHeaders);
73
72
 
@@ -1,5 +1,20 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "include": ["**/*.ts", "**/*.tsx"],
4
- "exclude": ["node_modules", "dist"],
2
+ "include": [
3
+ "src/**/*",
4
+ ],
5
+ "exclude": [
6
+ "node_modules",
7
+ "dist",
8
+ "build"
9
+ ],
10
+ "compilerOptions": {
11
+ "outDir": "./dist/esm",
12
+ "rootDir": "./src",
13
+ "sourceMap": true,
14
+ "declaration": true,
15
+ "target": "esnext",
16
+ "moduleResolution": "bundler",
17
+ "strictNullChecks": true,
18
+ "allowSyntheticDefaultImports": true
19
+ },
5
20
  }
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "include": [
3
3
  "./src/**/*.ts",
4
- "./src/**/*.tsx"
4
+ "./src/**/*.tsx",
5
5
  ],
6
6
  "exclude": [
7
7
  "node_modules",
@@ -15,6 +15,8 @@
15
15
  "declaration": true,
16
16
  "target": "esnext",
17
17
  "moduleResolution": "bundler",
18
+ "skipLibCheck": true,
19
+ "strictNullChecks": true,
18
20
  "allowSyntheticDefaultImports": true
19
21
  },
20
22
  }
package/.eslintrc DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": ["@smartive/eslint-config"],
3
- "parser": "@typescript-eslint/parser",
4
- "parserOptions": {
5
- "project": "./tsconfig.eslint.json"
6
- },
7
- "rules": {
8
- "@typescript-eslint/no-explicit-any": "off",
9
- "@typescript-eslint/no-floating-promises": ["error"],
10
- "no-constant-binary-expression": "error",
11
- "no-console": ["error", { "allow": ["info", "warn", "error", "trace", "time", "timeEnd"] }]
12
- }
13
- }