drizzle-graphql-plus 0.8.7 → 0.8.9

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.
@@ -0,0 +1,317 @@
1
+ import type { Column, Relation, SQL, Table } from "drizzle-orm";
2
+ import type { PgArray } from "drizzle-orm/pg-core";
3
+ import type {
4
+ GraphQLFieldConfigArgumentMap,
5
+ GraphQLFieldResolver,
6
+ GraphQLInputObjectType,
7
+ GraphQLInterfaceType,
8
+ GraphQLList,
9
+ GraphQLNonNull,
10
+ GraphQLObjectType,
11
+ GraphQLScalarType,
12
+ } from "graphql";
13
+ import type {
14
+ ConvertedColumn,
15
+ ConvertedRelationColumnWithArgs,
16
+ } from "../type-converter";
17
+
18
+ export type TableNamedRelations = {
19
+ relation: Relation;
20
+ targetTableName: string;
21
+ };
22
+
23
+ export type TableSelectArgs = {
24
+ offset: number;
25
+ limit: number;
26
+ where: Filters<Table>;
27
+ orderBy: OrderByArgs<Table>;
28
+ };
29
+
30
+ export type ProcessedTableSelectArgs = {
31
+ columns: Record<string, true>;
32
+ offset: number;
33
+ limit: number;
34
+ where: SQL;
35
+ orderBy: SQL[];
36
+ with?: Record<string, Partial<ProcessedTableSelectArgs>>;
37
+ };
38
+
39
+ export type SelectedColumnsRaw = [string, true][];
40
+
41
+ export type SelectedSQLColumns = [string, Column][];
42
+
43
+ export type SelectedColumns = {
44
+ [columnName in keyof Table["_"]["columns"]]: true;
45
+ };
46
+
47
+ export type CreatedResolver = {
48
+ name: string;
49
+ resolver: GraphQLFieldResolver<any, any>;
50
+ args: GraphQLFieldConfigArgumentMap;
51
+ };
52
+
53
+ export type ArgMapToArgsType<TArgMap extends GraphQLFieldConfigArgumentMap> = {
54
+ [Key in keyof TArgMap]?: TArgMap[Key] extends {
55
+ type: GraphQLScalarType<infer R, any>;
56
+ }
57
+ ? R
58
+ : never;
59
+ };
60
+
61
+ export type ColTypeIsNull<
62
+ TColumn extends Column,
63
+ TColType
64
+ > = TColumn["_"]["notNull"] extends true ? TColType : TColType | null;
65
+
66
+ export type ColTypeIsNullOrUndefined<
67
+ TColumn extends Column,
68
+ TColType
69
+ > = TColumn["_"]["notNull"] extends true
70
+ ? TColType
71
+ : TColType | null | undefined;
72
+
73
+ export type ColTypeIsNullOrUndefinedWithDefault<
74
+ TColumn extends Column,
75
+ TColType
76
+ > = TColumn["_"]["notNull"] extends true
77
+ ? TColumn["_"]["hasDefault"] extends true
78
+ ? TColType | null | undefined
79
+ : TColumn["defaultFn"] extends undefined
80
+ ? TColType
81
+ : TColType | null | undefined
82
+ : TColType | null | undefined;
83
+
84
+ export type GetColumnGqlDataType<TColumn extends Column> =
85
+ TColumn["dataType"] extends "boolean"
86
+ ? ColTypeIsNull<TColumn, boolean>
87
+ : TColumn["dataType"] extends "json"
88
+ ? TColumn["_"]["columnType"] extends "PgGeometryObject"
89
+ ? ColTypeIsNull<
90
+ TColumn,
91
+ {
92
+ x: number;
93
+ y: number;
94
+ }
95
+ >
96
+ : ColTypeIsNull<TColumn, string>
97
+ : TColumn["dataType"] extends "date" | "string" | "bigint"
98
+ ? TColumn["enumValues"] extends [string, ...string[]]
99
+ ? ColTypeIsNull<TColumn, TColumn["enumValues"][number]>
100
+ : ColTypeIsNull<TColumn, string>
101
+ : TColumn["dataType"] extends "number"
102
+ ? ColTypeIsNull<TColumn, number>
103
+ : TColumn["dataType"] extends "buffer"
104
+ ? ColTypeIsNull<TColumn, number[]>
105
+ : TColumn["dataType"] extends "array"
106
+ ? TColumn["columnType"] extends "PgVector"
107
+ ? ColTypeIsNull<TColumn, number[]>
108
+ : TColumn["columnType"] extends "PgGeometry"
109
+ ? ColTypeIsNullOrUndefinedWithDefault<TColumn, [number, number]>
110
+ : ColTypeIsNull<
111
+ TColumn,
112
+ Array<
113
+ GetColumnGqlDataType<
114
+ TColumn extends { baseColumn: Column }
115
+ ? TColumn["baseColumn"]
116
+ : never
117
+ > extends infer InnerColType
118
+ ? InnerColType extends null | undefined
119
+ ? never
120
+ : InnerColType
121
+ : never
122
+ >
123
+ >
124
+ : never;
125
+
126
+ export type GetColumnGqlInsertDataType<TColumn extends Column> =
127
+ TColumn["dataType"] extends "boolean"
128
+ ? ColTypeIsNullOrUndefinedWithDefault<TColumn, boolean>
129
+ : TColumn["dataType"] extends "json"
130
+ ? TColumn["_"]["columnType"] extends "PgGeometryObject"
131
+ ? ColTypeIsNullOrUndefinedWithDefault<
132
+ TColumn,
133
+ {
134
+ x: number;
135
+ y: number;
136
+ }
137
+ >
138
+ : ColTypeIsNullOrUndefinedWithDefault<TColumn, string>
139
+ : TColumn["dataType"] extends "date" | "string" | "bigint"
140
+ ? TColumn["enumValues"] extends [string, ...string[]]
141
+ ? ColTypeIsNullOrUndefinedWithDefault<
142
+ TColumn,
143
+ TColumn["enumValues"][number]
144
+ >
145
+ : ColTypeIsNullOrUndefinedWithDefault<TColumn, string>
146
+ : TColumn["dataType"] extends "number"
147
+ ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number>
148
+ : TColumn["dataType"] extends "buffer"
149
+ ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number[]>
150
+ : TColumn["dataType"] extends "array"
151
+ ? TColumn["columnType"] extends "PgVector"
152
+ ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number[]>
153
+ : TColumn["columnType"] extends "PgGeometry"
154
+ ? ColTypeIsNullOrUndefinedWithDefault<TColumn, [number, number]>
155
+ : ColTypeIsNullOrUndefinedWithDefault<
156
+ TColumn,
157
+ Array<
158
+ GetColumnGqlDataType<
159
+ TColumn extends { baseColumn: Column }
160
+ ? TColumn["baseColumn"]
161
+ : never
162
+ > extends infer InnerColType
163
+ ? InnerColType extends null | undefined
164
+ ? never
165
+ : InnerColType
166
+ : never
167
+ >
168
+ >
169
+ : never;
170
+
171
+ export type GetColumnGqlUpdateDataType<TColumn extends Column> =
172
+ TColumn["dataType"] extends "boolean"
173
+ ? boolean | null | undefined
174
+ : TColumn["dataType"] extends "json"
175
+ ? TColumn["_"]["columnType"] extends "PgGeometryObject"
176
+ ?
177
+ | {
178
+ x: number;
179
+ y: number;
180
+ }
181
+ | null
182
+ | undefined
183
+ : string | null | undefined
184
+ : TColumn["dataType"] extends "date" | "string" | "bigint"
185
+ ? TColumn["enumValues"] extends [string, ...string[]]
186
+ ? TColumn["enumValues"][number] | null | undefined
187
+ : string | null | undefined
188
+ : TColumn["dataType"] extends "number"
189
+ ? number | null | undefined
190
+ : TColumn["dataType"] extends "buffer"
191
+ ? number[] | null | undefined
192
+ : TColumn["dataType"] extends "array"
193
+ ? TColumn["columnType"] extends "PgVector"
194
+ ? number[] | null | undefined
195
+ : TColumn["columnType"] extends "PgGeometry"
196
+ ? [number, number] | null | undefined
197
+ :
198
+ | Array<
199
+ GetColumnGqlDataType<
200
+ TColumn extends { baseColumn: Column }
201
+ ? TColumn["baseColumn"]
202
+ : never
203
+ > extends infer InnerColType
204
+ ? InnerColType extends null | undefined
205
+ ? never
206
+ : InnerColType
207
+ : never
208
+ >
209
+ | null
210
+ | undefined
211
+ : never;
212
+
213
+ export type GetRemappedTableDataType<
214
+ TTable extends Table,
215
+ TColumns extends TTable["_"]["columns"] = TTable["_"]["columns"]
216
+ > = {
217
+ [K in keyof TColumns]: GetColumnGqlDataType<TColumns[K]>;
218
+ };
219
+
220
+ export type GetRemappedTableInsertDataType<TTable extends Table> = {
221
+ [K in keyof TTable["_"]["columns"]]: GetColumnGqlInsertDataType<
222
+ TTable["_"]["columns"][K]
223
+ >;
224
+ };
225
+
226
+ export type GetRemappedTableUpdateDataType<TTable extends Table> = {
227
+ [K in keyof TTable["_"]["columns"]]: GetColumnGqlUpdateDataType<
228
+ TTable["_"]["columns"][K]
229
+ >;
230
+ };
231
+
232
+ export type FilterColumnOperatorsCore<
233
+ TColumn extends Column,
234
+ TColType = GetColumnGqlDataType<TColumn>
235
+ > = Partial<{
236
+ eq: TColType;
237
+ ne: TColType;
238
+ lt: TColType;
239
+ lte: TColType;
240
+ gt: TColType;
241
+ gte: TColType;
242
+ like: string;
243
+ notLike: string;
244
+ ilike: string;
245
+ notIlike: string;
246
+ inArray: Array<TColType>;
247
+ notInArray: Array<TColType>;
248
+ isNull: boolean;
249
+ isNotNull: boolean;
250
+ }>;
251
+
252
+ export type FilterColumnOperators<
253
+ TColumn extends Column,
254
+ TOperators extends FilterColumnOperatorsCore<TColumn> = FilterColumnOperatorsCore<TColumn>
255
+ > = TOperators & {
256
+ OR?: TOperators[];
257
+ };
258
+
259
+ export type FiltersCore<TTable extends Table> = Partial<{
260
+ [Column in keyof TTable["_"]["columns"]]: FilterColumnOperatorsCore<
261
+ TTable["_"]["columns"][Column]
262
+ >;
263
+ }>;
264
+
265
+ export type Filters<
266
+ TTable extends Table,
267
+ TFilterType = FiltersCore<TTable>
268
+ > = TFilterType & {
269
+ OR?: TFilterType[];
270
+ };
271
+
272
+ export type OrderByArgs<TTable extends Table> = {
273
+ [Key in keyof TTable["_"]["columns"]]?: {
274
+ direction: "asc" | "desc";
275
+ priority: number;
276
+ };
277
+ };
278
+
279
+ export type GeneratedTableTypesInputs = {
280
+ insertInput: GraphQLInputObjectType;
281
+ updateInput: GraphQLInputObjectType;
282
+ tableOrder: GraphQLInputObjectType;
283
+ tableFilters: GraphQLInputObjectType;
284
+ };
285
+
286
+ export type GeneratedTableTypesOutputs<WithReturning extends boolean> =
287
+ WithReturning extends true
288
+ ? {
289
+ selectSingleOutput: GraphQLObjectType;
290
+ selectArrOutput: GraphQLNonNull<
291
+ GraphQLList<GraphQLNonNull<GraphQLObjectType>>
292
+ >;
293
+ singleTableItemOutput: GraphQLObjectType;
294
+ arrTableItemOutput: GraphQLNonNull<
295
+ GraphQLList<GraphQLNonNull<GraphQLObjectType>>
296
+ >;
297
+ tableFieldsInterface: GraphQLInterfaceType;
298
+ }
299
+ : {
300
+ selectSingleOutput: GraphQLObjectType;
301
+ selectArrOutput: GraphQLNonNull<
302
+ GraphQLList<GraphQLNonNull<GraphQLObjectType>>
303
+ >;
304
+ tableFieldsInterface: GraphQLInterfaceType;
305
+ };
306
+
307
+ export type GeneratedTableTypes<WithReturning extends boolean> = {
308
+ inputs: GeneratedTableTypesInputs;
309
+ outputs: GeneratedTableTypesOutputs<WithReturning>;
310
+ };
311
+
312
+ export type SelectData<TWithOrder extends boolean> = {
313
+ filters: GraphQLInputObjectType;
314
+ tableFields: Record<string, ConvertedColumn>;
315
+ relationFields: Record<string, ConvertedRelationColumnWithArgs>;
316
+ order: TWithOrder extends true ? GraphQLInputObjectType : undefined;
317
+ };
@@ -0,0 +1,9 @@
1
+ export const uncapitalize = <T extends string>(input: T) =>
2
+ (input.length
3
+ ? `${input[0]!.toLocaleLowerCase()}${input.length > 1 ? input.slice(1, input.length) : ''}`
4
+ : input) as Uncapitalize<T>;
5
+
6
+ export const capitalize = <T extends string>(input: T) =>
7
+ (input.length
8
+ ? `${input[0]!.toLocaleUpperCase()}${input.length > 1 ? input.slice(1, input.length) : ''}`
9
+ : input) as Capitalize<T>;
@@ -0,0 +1,162 @@
1
+ import { type Column, getTableColumns, type Table } from 'drizzle-orm';
2
+ import { GraphQLError } from 'graphql';
3
+ import { TableNamedRelations } from '../builders';
4
+
5
+ export const remapToGraphQLCore = (
6
+ key: string,
7
+ value: any,
8
+ tableName: string,
9
+ column: Column,
10
+ relationMap?: Record<string, Record<string, TableNamedRelations>>,
11
+ ): any => {
12
+ if (value instanceof Date) return value.toISOString();
13
+
14
+ if (value instanceof Buffer) return Array.from(value);
15
+
16
+ if (typeof value === 'bigint') return value.toString();
17
+
18
+ if (Array.isArray(value)) {
19
+ const relations = relationMap?.[tableName];
20
+ if (relations?.[key]) {
21
+ return remapToGraphQLArrayOutput(
22
+ value,
23
+ relations[key]!.targetTableName,
24
+ relations[key]!.relation.referencedTable,
25
+ relationMap,
26
+ );
27
+ }
28
+ if (column.columnType === 'PgGeometry' || column.columnType === 'PgVector') return value;
29
+
30
+ return value.map((arrVal) => remapToGraphQLCore(key, arrVal, tableName, column, relationMap));
31
+ }
32
+
33
+ if (typeof value === 'object') {
34
+ const relations = relationMap?.[tableName];
35
+ if (relations?.[key]) {
36
+ return remapToGraphQLSingleOutput(
37
+ value,
38
+ relations[key]!.targetTableName,
39
+ relations[key]!.relation.referencedTable,
40
+ relationMap,
41
+ );
42
+ }
43
+ if (column.columnType === 'PgGeometryObject') return value;
44
+
45
+ return JSON.stringify(value);
46
+ }
47
+
48
+ return value;
49
+ };
50
+
51
+ export const remapToGraphQLSingleOutput = (
52
+ queryOutput: Record<string, any>,
53
+ tableName: string,
54
+ table: Table,
55
+ relationMap?: Record<string, Record<string, TableNamedRelations>>,
56
+ ) => {
57
+ for (const [key, value] of Object.entries(queryOutput)) {
58
+ if (value === undefined || value === null) {
59
+ delete queryOutput[key];
60
+ } else {
61
+ queryOutput[key] = remapToGraphQLCore(key, value, tableName, table[key as keyof Table]! as Column, relationMap);
62
+ }
63
+ }
64
+
65
+ return queryOutput;
66
+ };
67
+
68
+ export const remapToGraphQLArrayOutput = (
69
+ queryOutput: Record<string, any>[],
70
+ tableName: string,
71
+ table: Table,
72
+ relationMap?: Record<string, Record<string, TableNamedRelations>>,
73
+ ) => {
74
+ for (const entry of queryOutput) {
75
+ remapToGraphQLSingleOutput(entry, tableName, table, relationMap);
76
+ }
77
+
78
+ return queryOutput;
79
+ };
80
+
81
+ export const remapFromGraphQLCore = (value: any, column: Column, columnName: string) => {
82
+ switch (column.dataType) {
83
+ case 'date': {
84
+ const formatted = new Date(value);
85
+ if (Number.isNaN(formatted.getTime())) throw new GraphQLError(`Field '${columnName}' is not a valid date!`);
86
+
87
+ return formatted;
88
+ }
89
+
90
+ case 'buffer': {
91
+ if (!Array.isArray(value)) {
92
+ throw new GraphQLError(`Field '${columnName}' is not an array!`);
93
+ }
94
+
95
+ return Buffer.from(value);
96
+ }
97
+
98
+ case 'json': {
99
+ if (column.columnType === 'PgGeometryObject') return value;
100
+
101
+ try {
102
+ return JSON.parse(value);
103
+ } catch (e) {
104
+ throw new GraphQLError(
105
+ `Invalid JSON in field '${columnName}':\n${e instanceof Error ? e.message : 'Unknown error'}`,
106
+ );
107
+ }
108
+ }
109
+
110
+ case 'array': {
111
+ if (!Array.isArray(value)) {
112
+ throw new GraphQLError(`Field '${columnName}' is not an array!`);
113
+ }
114
+
115
+ if (column.columnType === 'PgGeometry' && value.length !== 2) {
116
+ throw new GraphQLError(
117
+ `Invalid float tuple in field '${columnName}': expected array with length of 2, received ${value.length}`,
118
+ );
119
+ }
120
+
121
+ return value;
122
+ }
123
+
124
+ case 'bigint': {
125
+ try {
126
+ return BigInt(value);
127
+ } catch (error) {
128
+ throw new GraphQLError(`Field '${columnName}' is not a BigInt!`);
129
+ }
130
+ }
131
+
132
+ default: {
133
+ return value;
134
+ }
135
+ }
136
+ };
137
+
138
+ export const remapFromGraphQLSingleInput = (queryInput: Record<string, any>, table: Table) => {
139
+ for (const [key, value] of Object.entries(queryInput)) {
140
+ if (value === undefined) {
141
+ delete queryInput[key];
142
+ } else {
143
+ const column = getTableColumns(table)[key];
144
+ if (!column) throw new GraphQLError(`Unknown column: ${key}`);
145
+
146
+ if (value === null && column.notNull) {
147
+ delete queryInput[key];
148
+ continue;
149
+ }
150
+
151
+ queryInput[key] = remapFromGraphQLCore(value, column, key);
152
+ }
153
+ }
154
+
155
+ return queryInput;
156
+ };
157
+
158
+ export const remapFromGraphQLArrayInput = (queryInput: Record<string, any>[], table: Table) => {
159
+ for (const entry of queryInput) remapFromGraphQLSingleInput(entry, table);
160
+
161
+ return queryInput;
162
+ };
@@ -0,0 +1,148 @@
1
+ import { is } from 'drizzle-orm';
2
+ import { MySqlInt, MySqlSerial } from 'drizzle-orm/mysql-core';
3
+ import { PgInteger, PgSerial } from 'drizzle-orm/pg-core';
4
+ import { SQLiteInteger } from 'drizzle-orm/sqlite-core';
5
+ import {
6
+ GraphQLBoolean,
7
+ GraphQLEnumType,
8
+ GraphQLFloat,
9
+ GraphQLInputObjectType,
10
+ GraphQLInt,
11
+ GraphQLList,
12
+ GraphQLNonNull,
13
+ GraphQLObjectType,
14
+ GraphQLScalarType,
15
+ GraphQLString,
16
+ } from 'graphql';
17
+
18
+ import type { Column } from 'drizzle-orm';
19
+ import type { PgArray } from 'drizzle-orm/pg-core';
20
+ import { capitalize } from '../case-ops';
21
+ import type { ConvertedColumn } from './types';
22
+
23
+ const allowedNameChars = /^[a-zA-Z0-9_]+$/;
24
+
25
+ const enumMap = new WeakMap<Object, GraphQLEnumType>();
26
+ const generateEnumCached = (column: Column, columnName: string, tableName: string): GraphQLEnumType => {
27
+ if (enumMap.has(column)) return enumMap.get(column)!;
28
+
29
+ const gqlEnum = new GraphQLEnumType({
30
+ name: `${capitalize(tableName)}${capitalize(columnName)}Enum`,
31
+ values: Object.fromEntries(column.enumValues!.map((e, index) => [allowedNameChars.test(e) ? e : `Option${index}`, {
32
+ value: e,
33
+ description: `Value: ${e}`,
34
+ }])),
35
+ });
36
+
37
+ enumMap.set(column, gqlEnum);
38
+
39
+ return gqlEnum;
40
+ };
41
+
42
+ const geoXyType = new GraphQLObjectType({
43
+ name: 'PgGeometryObject',
44
+ fields: {
45
+ x: { type: GraphQLFloat },
46
+ y: { type: GraphQLFloat },
47
+ },
48
+ });
49
+
50
+ const geoXyInputType = new GraphQLInputObjectType({
51
+ name: 'PgGeometryObjectInput',
52
+ fields: {
53
+ x: { type: GraphQLFloat },
54
+ y: { type: GraphQLFloat },
55
+ },
56
+ });
57
+
58
+ const columnToGraphQLCore = (
59
+ column: Column,
60
+ columnName: string,
61
+ tableName: string,
62
+ isInput: boolean,
63
+ ): ConvertedColumn<boolean> => {
64
+ switch (column.dataType) {
65
+ case 'boolean':
66
+ return { type: GraphQLBoolean, description: 'Boolean' };
67
+ case 'json':
68
+ return column.columnType === 'PgGeometryObject'
69
+ ? {
70
+ type: isInput ? geoXyInputType : geoXyType,
71
+ description: 'Geometry points XY',
72
+ }
73
+ : { type: GraphQLString, description: 'JSON' };
74
+ case 'date':
75
+ return { type: GraphQLString, description: 'Date' };
76
+ case 'string':
77
+ if (column.enumValues?.length) return { type: generateEnumCached(column, columnName, tableName) };
78
+
79
+ return { type: GraphQLString, description: 'String' };
80
+ case 'bigint':
81
+ return { type: GraphQLString, description: 'BigInt' };
82
+ case 'number':
83
+ return is(column, PgInteger)
84
+ || is(column, PgSerial)
85
+ || is(column, MySqlInt)
86
+ || is(column, MySqlSerial)
87
+ || is(column, SQLiteInteger)
88
+ ? { type: GraphQLInt, description: 'Integer' }
89
+ : { type: GraphQLFloat, description: 'Float' };
90
+ case 'buffer':
91
+ return { type: new GraphQLList(new GraphQLNonNull(GraphQLInt)), description: 'Buffer' };
92
+ case 'array': {
93
+ if (column.columnType === 'PgVector') {
94
+ return {
95
+ type: new GraphQLList(new GraphQLNonNull(GraphQLFloat)),
96
+ description: 'Array<Float>',
97
+ };
98
+ }
99
+
100
+ if (column.columnType === 'PgGeometry') {
101
+ return {
102
+ type: new GraphQLList(new GraphQLNonNull(GraphQLFloat)),
103
+ description: 'Tuple<[Float, Float]>',
104
+ };
105
+ }
106
+
107
+ const innerType = columnToGraphQLCore(
108
+ (column as Column as PgArray<any, any>).baseColumn,
109
+ columnName,
110
+ tableName,
111
+ isInput,
112
+ );
113
+
114
+ return {
115
+ type: new GraphQLList(new GraphQLNonNull(innerType.type as GraphQLScalarType)),
116
+ description: `Array<${innerType.description}>`,
117
+ };
118
+ }
119
+ case 'custom':
120
+ default:
121
+ throw new Error(`Drizzle-GraphQL Error: Type ${column.dataType} is not implemented!`);
122
+ }
123
+ };
124
+
125
+ export const drizzleColumnToGraphQLType = <TColumn extends Column, TIsInput extends boolean>(
126
+ column: TColumn,
127
+ columnName: string,
128
+ tableName: string,
129
+ forceNullable = false,
130
+ defaultIsNullable = false,
131
+ isInput: TIsInput = false as TIsInput,
132
+ ): ConvertedColumn<TIsInput> => {
133
+ const typeDesc = columnToGraphQLCore(column, columnName, tableName, isInput);
134
+ const noDesc = ['string', 'boolean', 'number'];
135
+ if (noDesc.find((e) => e === column.dataType)) delete typeDesc.description;
136
+
137
+ if (forceNullable) return typeDesc as ConvertedColumn<TIsInput>;
138
+ if (column.notNull && !(defaultIsNullable && (column.hasDefault || column.defaultFn))) {
139
+ return {
140
+ type: new GraphQLNonNull(typeDesc.type),
141
+ description: typeDesc.description,
142
+ } as ConvertedColumn<TIsInput>;
143
+ }
144
+
145
+ return typeDesc as ConvertedColumn<TIsInput>;
146
+ };
147
+
148
+ export * from './types';
@@ -0,0 +1,54 @@
1
+ import type {
2
+ GraphQLEnumType,
3
+ GraphQLFieldConfig,
4
+ GraphQLInputObjectType,
5
+ GraphQLList,
6
+ GraphQLNonNull,
7
+ GraphQLObjectType,
8
+ GraphQLScalarType,
9
+ } from 'graphql';
10
+
11
+ export type ConvertedColumn<TIsInput extends boolean = false> = {
12
+ type:
13
+ | GraphQLScalarType
14
+ | GraphQLEnumType
15
+ | GraphQLNonNull<GraphQLScalarType>
16
+ | GraphQLNonNull<GraphQLEnumType>
17
+ | GraphQLList<GraphQLScalarType>
18
+ | GraphQLList<GraphQLNonNull<GraphQLScalarType>>
19
+ | GraphQLNonNull<GraphQLList<GraphQLScalarType>>
20
+ | GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLScalarType>>>
21
+ | (TIsInput extends true ?
22
+ | GraphQLInputObjectType
23
+ | GraphQLNonNull<GraphQLInputObjectType>
24
+ | GraphQLList<GraphQLInputObjectType>
25
+ | GraphQLNonNull<GraphQLList<GraphQLInputObjectType>>
26
+ | GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLInputObjectType>>>
27
+ :
28
+ | GraphQLObjectType
29
+ | GraphQLNonNull<GraphQLObjectType>
30
+ | GraphQLList<GraphQLObjectType>
31
+ | GraphQLNonNull<GraphQLList<GraphQLObjectType>>
32
+ | GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLObjectType>>>);
33
+ description?: string;
34
+ };
35
+
36
+ export type ConvertedColumnWithArgs = ConvertedColumn & {
37
+ args?: GraphQLFieldConfig<any, any>['args'];
38
+ };
39
+
40
+ export type ConvertedInputColumn = {
41
+ type: GraphQLInputObjectType;
42
+ description?: string;
43
+ };
44
+
45
+ export type ConvertedRelationColumn = {
46
+ type:
47
+ | GraphQLObjectType
48
+ | GraphQLNonNull<GraphQLObjectType>
49
+ | GraphQLNonNull<GraphQLList<GraphQLNonNull<GraphQLObjectType>>>;
50
+ };
51
+
52
+ export type ConvertedRelationColumnWithArgs = ConvertedRelationColumn & {
53
+ args?: GraphQLFieldConfig<any, any>['args'];
54
+ };