@drizzle-graphql-suite/schema 0.5.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/LICENSE +21 -0
- package/README.md +348 -0
- package/adapters/pg.d.ts +10 -0
- package/adapters/types.d.ts +11 -0
- package/case-ops.d.ts +2 -0
- package/codegen.d.ts +12 -0
- package/data-mappers.d.ts +12 -0
- package/graphql/scalars.d.ts +2 -0
- package/graphql/type-builder.d.ts +7 -0
- package/index.d.ts +26 -0
- package/index.js +1812 -0
- package/package.json +41 -0
- package/schema-builder.d.ts +65 -0
- package/types.d.ts +117 -0
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@drizzle-graphql-suite/schema",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "GraphQL schema builder with CRUD operations, relation filtering, and hooks from Drizzle ORM",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "https://github.com/dmythro",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/annexare/drizzle-graphql-suite.git",
|
|
10
|
+
"directory": "packages/schema"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/annexare/drizzle-graphql-suite/tree/main/packages/schema#readme",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"drizzle",
|
|
15
|
+
"graphql",
|
|
16
|
+
"schema",
|
|
17
|
+
"orm",
|
|
18
|
+
"postgresql",
|
|
19
|
+
"crud",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"main": "./index.js",
|
|
27
|
+
"types": "./index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./index.d.ts",
|
|
31
|
+
"import": "./index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"graphql-parse-resolve-info": "4.14.1"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"drizzle-orm": ">=0.44.0",
|
|
39
|
+
"graphql": ">=16.3.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type PgDatabase } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { GraphQLSchema } from 'graphql';
|
|
3
|
+
import type { BuildSchemaConfig, GeneratedEntities } from './types';
|
|
4
|
+
export declare class SchemaBuilder {
|
|
5
|
+
private db;
|
|
6
|
+
private tables;
|
|
7
|
+
private relationMap;
|
|
8
|
+
private relationalSchema;
|
|
9
|
+
private tableNamesMap;
|
|
10
|
+
private config;
|
|
11
|
+
private hooks;
|
|
12
|
+
private adapter;
|
|
13
|
+
private suffixes;
|
|
14
|
+
private limitRelationDepth;
|
|
15
|
+
private limitSelfRelationDepth;
|
|
16
|
+
private excludedTables;
|
|
17
|
+
private tableOperations;
|
|
18
|
+
private pruneRelations;
|
|
19
|
+
private filterTypes;
|
|
20
|
+
private orderByTypes;
|
|
21
|
+
private filterValueTypes;
|
|
22
|
+
private selectFieldTypes;
|
|
23
|
+
private innerOrder;
|
|
24
|
+
constructor(db: PgDatabase<any, any, any>, config?: BuildSchemaConfig);
|
|
25
|
+
private toFieldMap;
|
|
26
|
+
buildEntities(): GeneratedEntities;
|
|
27
|
+
build(): {
|
|
28
|
+
schema: GraphQLSchema;
|
|
29
|
+
entities: GeneratedEntities;
|
|
30
|
+
};
|
|
31
|
+
private logDebugInfo;
|
|
32
|
+
private extractTables;
|
|
33
|
+
private getTable;
|
|
34
|
+
private buildRelationMap;
|
|
35
|
+
private getFilterType;
|
|
36
|
+
private getOrderByType;
|
|
37
|
+
private getFilterValues;
|
|
38
|
+
private getSelectFields;
|
|
39
|
+
private generateColumnFilterValues;
|
|
40
|
+
private generateSelectFields;
|
|
41
|
+
private generateTableTypes;
|
|
42
|
+
private buildRelationFilterFields;
|
|
43
|
+
private createQueryResolver;
|
|
44
|
+
private createSingleQueryResolver;
|
|
45
|
+
private createCountResolver;
|
|
46
|
+
private createInsertResolver;
|
|
47
|
+
private createInsertSingleResolver;
|
|
48
|
+
private createUpdateResolver;
|
|
49
|
+
private createDeleteResolver;
|
|
50
|
+
private extractColumnFilters;
|
|
51
|
+
private extractTableColumnFilters;
|
|
52
|
+
/** Combined filter extraction: column filters + relation filters */
|
|
53
|
+
private extractAllFilters;
|
|
54
|
+
private extractRelationFilters;
|
|
55
|
+
private buildExistsSubquery;
|
|
56
|
+
private buildJoinCondition;
|
|
57
|
+
private extractOrderBy;
|
|
58
|
+
private extractColumns;
|
|
59
|
+
private extractColumnsSQLFormat;
|
|
60
|
+
private getFieldsByTypeName;
|
|
61
|
+
private extractRelationsParams;
|
|
62
|
+
private extractRelationsParamsInner;
|
|
63
|
+
private executeWithHooks;
|
|
64
|
+
private executeCountQuery;
|
|
65
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { GraphQLFieldConfig, GraphQLInputObjectType, GraphQLObjectType, GraphQLResolveInfo } from 'graphql';
|
|
2
|
+
export type GeneratedEntities = {
|
|
3
|
+
queries: Record<string, GraphQLFieldConfig<any, any>>;
|
|
4
|
+
mutations: Record<string, GraphQLFieldConfig<any, any>>;
|
|
5
|
+
inputs: Record<string, GraphQLInputObjectType>;
|
|
6
|
+
types: Record<string, GraphQLObjectType>;
|
|
7
|
+
};
|
|
8
|
+
export type OperationType = 'query' | 'querySingle' | 'count' | 'insert' | 'insertSingle' | 'update' | 'delete';
|
|
9
|
+
export type HookContext = {
|
|
10
|
+
args: any;
|
|
11
|
+
context: any;
|
|
12
|
+
info: GraphQLResolveInfo;
|
|
13
|
+
};
|
|
14
|
+
export type BeforeHookResult = {
|
|
15
|
+
args?: any;
|
|
16
|
+
data?: any;
|
|
17
|
+
};
|
|
18
|
+
export type BeforeHookFn = (ctx: HookContext) => Promise<BeforeHookResult | undefined> | BeforeHookResult | undefined;
|
|
19
|
+
export type AfterHookContext = {
|
|
20
|
+
result: any;
|
|
21
|
+
beforeData: any;
|
|
22
|
+
context: any;
|
|
23
|
+
info: GraphQLResolveInfo;
|
|
24
|
+
};
|
|
25
|
+
export type AfterHookFn = (ctx: AfterHookContext) => Promise<any> | any;
|
|
26
|
+
export type ResolveHookContext = HookContext & {
|
|
27
|
+
defaultResolve: (overrideArgs?: any) => Promise<any>;
|
|
28
|
+
};
|
|
29
|
+
export type ResolveHookFn = (ctx: ResolveHookContext) => Promise<any> | any;
|
|
30
|
+
export type OperationHooks = {
|
|
31
|
+
before?: BeforeHookFn;
|
|
32
|
+
after?: AfterHookFn;
|
|
33
|
+
} | {
|
|
34
|
+
resolve: ResolveHookFn;
|
|
35
|
+
};
|
|
36
|
+
export type TableHookConfig = {
|
|
37
|
+
[K in OperationType]?: OperationHooks;
|
|
38
|
+
};
|
|
39
|
+
export type HooksConfig = {
|
|
40
|
+
[tableName: string]: TableHookConfig;
|
|
41
|
+
};
|
|
42
|
+
export type TableOperations = {
|
|
43
|
+
/** Generate query operations (list, single, count). @default true */
|
|
44
|
+
queries?: boolean;
|
|
45
|
+
/** Generate mutation operations (insert, insertSingle, update, delete). @default follows global `mutations` */
|
|
46
|
+
mutations?: boolean;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Controls how a specific relation expands in the schema.
|
|
50
|
+
* - `false`: relation field omitted entirely from parent type
|
|
51
|
+
* - `'leaf'`: relation expands with scalar columns only (no child relations)
|
|
52
|
+
* - `{ only: string[] }`: relation expands with only the listed child relation fields
|
|
53
|
+
*/
|
|
54
|
+
export type RelationPruneRule = false | 'leaf' | {
|
|
55
|
+
only: string[];
|
|
56
|
+
};
|
|
57
|
+
export type BuildSchemaConfig = {
|
|
58
|
+
/**
|
|
59
|
+
* Set to `false` to omit mutations from the schema.
|
|
60
|
+
* @default true
|
|
61
|
+
*/
|
|
62
|
+
mutations?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Limits depth of generated relation fields on queries.
|
|
65
|
+
* Non-negative integer or undefined (no limit).
|
|
66
|
+
* Set to 0 to omit relations altogether.
|
|
67
|
+
* @default 3
|
|
68
|
+
*/
|
|
69
|
+
limitRelationDepth?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Max occurrences of the same table via direct self-relations in a type path.
|
|
72
|
+
* - 1 = self-relation fields are omitted entirely (default)
|
|
73
|
+
* - 2 = one level of self-relation expansion (e.g., item.parent exists but
|
|
74
|
+
* the nested item has no parent/children fields)
|
|
75
|
+
* Only applies to direct self-relations (source table === target table).
|
|
76
|
+
* Cross-table paths that revisit a table are governed by limitRelationDepth.
|
|
77
|
+
* @default 1
|
|
78
|
+
*/
|
|
79
|
+
limitSelfRelationDepth?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Customizes query name suffixes.
|
|
82
|
+
* @default { list: '', single: 'Single' }
|
|
83
|
+
*/
|
|
84
|
+
suffixes?: {
|
|
85
|
+
list?: string;
|
|
86
|
+
single?: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Per-table hooks for queries and mutations.
|
|
90
|
+
* Keys are table names as they appear in the Drizzle schema.
|
|
91
|
+
*/
|
|
92
|
+
hooks?: HooksConfig;
|
|
93
|
+
/**
|
|
94
|
+
* Per-table configuration: exclude tables or limit operations.
|
|
95
|
+
* Table names must match the keys in the Drizzle schema object.
|
|
96
|
+
*/
|
|
97
|
+
tables?: {
|
|
98
|
+
/** Tables to completely exclude (no types, no operations, relations to them skipped). */
|
|
99
|
+
exclude?: string[];
|
|
100
|
+
/** Per-table operation overrides. Tables not listed get default behavior. */
|
|
101
|
+
config?: Record<string, TableOperations>;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Fine-grained per-relation pruning rules.
|
|
105
|
+
* Keys are `tableName.relationName` (e.g., `'asset.childAssets': false`).
|
|
106
|
+
*/
|
|
107
|
+
pruneRelations?: Record<string, RelationPruneRule>;
|
|
108
|
+
/**
|
|
109
|
+
* Enable debug logging for schema diagnostics.
|
|
110
|
+
* - `true`: logs SDL byte size and type count
|
|
111
|
+
* - `{ schemaSize?: boolean; relationTree?: boolean }`: selective logging
|
|
112
|
+
*/
|
|
113
|
+
debug?: boolean | {
|
|
114
|
+
schemaSize?: boolean;
|
|
115
|
+
relationTree?: boolean;
|
|
116
|
+
};
|
|
117
|
+
};
|