@constructive-io/graphql-codegen 4.14.1 → 4.14.3

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.
@@ -96,11 +96,14 @@ function generate(options) {
96
96
  });
97
97
  hasInvalidation = true;
98
98
  }
99
+ // Condition types (PostGraphile simple equality filters)
100
+ const conditionEnabled = config.codegen?.condition !== false;
99
101
  // 4. Generate table-based query hooks (queries/*.ts)
100
102
  const queryHooks = (0, queries_1.generateAllQueryHooks)(tables, {
101
103
  reactQueryEnabled,
102
104
  useCentralizedKeys,
103
105
  hasRelationships,
106
+ condition: conditionEnabled,
104
107
  });
105
108
  for (const hook of queryHooks) {
106
109
  files.push({
@@ -175,9 +175,9 @@ function generateModelFile(table, _useSharedTypes, options) {
175
175
  const findManyTypeArgs = [
176
176
  (sel) => sel,
177
177
  () => t.tsTypeReference(t.identifier(whereTypeName)),
178
- ...(conditionTypeName
179
- ? [() => t.tsTypeReference(t.identifier(conditionTypeName))]
180
- : []),
178
+ conditionTypeName
179
+ ? () => t.tsTypeReference(t.identifier(conditionTypeName))
180
+ : () => t.tsNeverKeyword(),
181
181
  () => t.tsTypeReference(t.identifier(orderByTypeName)),
182
182
  ];
183
183
  const argsType = (sel) => t.tsTypeReference(t.identifier('FindManyArgs'), t.tsTypeParameterInstantiation(findManyTypeArgs.map(fn => fn(sel))));
@@ -7,6 +7,7 @@ export interface QueryGeneratorOptions {
7
7
  reactQueryEnabled?: boolean;
8
8
  useCentralizedKeys?: boolean;
9
9
  hasRelationships?: boolean;
10
+ condition?: boolean;
10
11
  }
11
12
  export declare function generateListQueryHook(table: CleanTable, options?: QueryGeneratorOptions): GeneratedQueryFile;
12
13
  export declare function generateSingleQueryHook(table: CleanTable, options?: QueryGeneratorOptions): GeneratedQueryFile | null;
@@ -49,12 +49,13 @@ const babel_ast_1 = require("./babel-ast");
49
49
  const hooks_ast_1 = require("./hooks-ast");
50
50
  const utils_1 = require("./utils");
51
51
  function generateListQueryHook(table, options = {}) {
52
- const { reactQueryEnabled = true, useCentralizedKeys = true, hasRelationships = false, } = options;
52
+ const { reactQueryEnabled = true, useCentralizedKeys = true, hasRelationships = false, condition: conditionEnabled = true, } = options;
53
53
  const { typeName, pluralName, singularName } = (0, utils_1.getTableNames)(table);
54
54
  const hookName = (0, utils_1.getListQueryHookName)(table);
55
55
  const queryName = (0, utils_1.getAllRowsQueryName)(table);
56
56
  const filterTypeName = (0, utils_1.getFilterTypeName)(table);
57
57
  const orderByTypeName = (0, utils_1.getOrderByTypeName)(table);
58
+ const conditionTypeName = conditionEnabled ? (0, utils_1.getConditionTypeName)(table) : undefined;
58
59
  const keysName = `${(0, utils_1.lcFirst)(typeName)}Keys`;
59
60
  const scopeTypeName = `${typeName}Scope`;
60
61
  const selectTypeName = `${typeName}Select`;
@@ -75,7 +76,10 @@ function generateListQueryHook(table, options = {}) {
75
76
  statements.push((0, hooks_ast_1.createImportDeclaration)('../query-keys', [scopeTypeName], true));
76
77
  }
77
78
  }
78
- statements.push((0, hooks_ast_1.createImportDeclaration)('../../orm/input-types', [selectTypeName, relationTypeName, filterTypeName, orderByTypeName], true));
79
+ const inputTypeImports = [selectTypeName, relationTypeName, filterTypeName, orderByTypeName];
80
+ if (conditionTypeName)
81
+ inputTypeImports.push(conditionTypeName);
82
+ statements.push((0, hooks_ast_1.createImportDeclaration)('../../orm/input-types', inputTypeImports, true));
79
83
  statements.push((0, hooks_ast_1.createImportDeclaration)('../../orm/select-types', [
80
84
  'FindManyArgs',
81
85
  'InferSelectResult',
@@ -83,7 +87,10 @@ function generateListQueryHook(table, options = {}) {
83
87
  'HookStrictSelect',
84
88
  ], true));
85
89
  // Re-exports
86
- statements.push((0, hooks_ast_1.createTypeReExport)([selectTypeName, relationTypeName, filterTypeName, orderByTypeName], '../../orm/input-types'));
90
+ const reExportTypes = [selectTypeName, relationTypeName, filterTypeName, orderByTypeName];
91
+ if (conditionTypeName)
92
+ reExportTypes.push(conditionTypeName);
93
+ statements.push((0, hooks_ast_1.createTypeReExport)(reExportTypes, '../../orm/input-types'));
87
94
  // Query key
88
95
  if (useCentralizedKeys) {
89
96
  const keyDecl = t.exportNamedDeclaration(t.variableDeclaration('const', [
@@ -95,12 +102,14 @@ function generateListQueryHook(table, options = {}) {
95
102
  statements.push(keyDecl);
96
103
  }
97
104
  else {
105
+ const findManyKeyTypeArgs = [
106
+ t.tsUnknownKeyword(),
107
+ (0, hooks_ast_1.typeRef)(filterTypeName),
108
+ conditionTypeName ? (0, hooks_ast_1.typeRef)(conditionTypeName) : t.tsNeverKeyword(),
109
+ (0, hooks_ast_1.typeRef)(orderByTypeName),
110
+ ];
98
111
  const keyFn = t.arrowFunctionExpression([
99
- (0, hooks_ast_1.createFunctionParam)('variables', (0, hooks_ast_1.typeRef)('FindManyArgs', [
100
- t.tsUnknownKeyword(),
101
- (0, hooks_ast_1.typeRef)(filterTypeName),
102
- (0, hooks_ast_1.typeRef)(orderByTypeName),
103
- ]), true),
112
+ (0, hooks_ast_1.createFunctionParam)('variables', (0, hooks_ast_1.typeRef)('FindManyArgs', findManyKeyTypeArgs), true),
104
113
  ], (0, babel_ast_1.asConst)(t.arrayExpression([
105
114
  t.stringLiteral(typeName.toLowerCase()),
106
115
  t.stringLiteral('list'),
@@ -97,6 +97,12 @@ const FILTER_CONFIGS = [
97
97
  operators: ['equality', 'distinct', 'inArray', 'comparison', 'inet'],
98
98
  },
99
99
  { name: 'FullTextFilter', tsType: 'string', operators: ['fulltext'] },
100
+ // Vector filter (for pgvector embedding columns)
101
+ {
102
+ name: 'VectorFilter',
103
+ tsType: 'number[]',
104
+ operators: ['equality', 'distinct'],
105
+ },
100
106
  // List filters
101
107
  {
102
108
  name: 'StringListFilter',
@@ -91,11 +91,14 @@ export function generate(options) {
91
91
  });
92
92
  hasInvalidation = true;
93
93
  }
94
+ // Condition types (PostGraphile simple equality filters)
95
+ const conditionEnabled = config.codegen?.condition !== false;
94
96
  // 4. Generate table-based query hooks (queries/*.ts)
95
97
  const queryHooks = generateAllQueryHooks(tables, {
96
98
  reactQueryEnabled,
97
99
  useCentralizedKeys,
98
100
  hasRelationships,
101
+ condition: conditionEnabled,
99
102
  });
100
103
  for (const hook of queryHooks) {
101
104
  files.push({
@@ -138,9 +138,9 @@ export function generateModelFile(table, _useSharedTypes, options) {
138
138
  const findManyTypeArgs = [
139
139
  (sel) => sel,
140
140
  () => t.tsTypeReference(t.identifier(whereTypeName)),
141
- ...(conditionTypeName
142
- ? [() => t.tsTypeReference(t.identifier(conditionTypeName))]
143
- : []),
141
+ conditionTypeName
142
+ ? () => t.tsTypeReference(t.identifier(conditionTypeName))
143
+ : () => t.tsNeverKeyword(),
144
144
  () => t.tsTypeReference(t.identifier(orderByTypeName)),
145
145
  ];
146
146
  const argsType = (sel) => t.tsTypeReference(t.identifier('FindManyArgs'), t.tsTypeParameterInstantiation(findManyTypeArgs.map(fn => fn(sel))));
@@ -7,6 +7,7 @@ export interface QueryGeneratorOptions {
7
7
  reactQueryEnabled?: boolean;
8
8
  useCentralizedKeys?: boolean;
9
9
  hasRelationships?: boolean;
10
+ condition?: boolean;
10
11
  }
11
12
  export declare function generateListQueryHook(table: CleanTable, options?: QueryGeneratorOptions): GeneratedQueryFile;
12
13
  export declare function generateSingleQueryHook(table: CleanTable, options?: QueryGeneratorOptions): GeneratedQueryFile | null;
@@ -9,14 +9,15 @@
9
9
  import * as t from '@babel/types';
10
10
  import { asConst } from './babel-ast';
11
11
  import { addJSDocComment, buildFindManyCallExpr, buildFindOneCallExpr, buildListSelectionArgsCall, buildSelectionArgsCall, callExpr, createFunctionParam, createImportDeclaration, createSAndTDataTypeParams, createSTypeParam, createTypeReExport, destructureParamsWithSelection, destructureParamsWithSelectionAndScope, exportAsyncDeclareFunction, exportAsyncFunction, exportDeclareFunction, exportFunction, generateHookFileCode, listQueryResultType, listSelectionConfigType, objectProp, omitType, returnUseQuery, scopeTypeLiteral, selectionConfigType, singleQueryResultType, spreadObj, sRef, typeRef, useQueryOptionsImplType, voidStatement, withFieldsListSelectionType, withFieldsSelectionType, } from './hooks-ast';
12
- import { getAllRowsQueryName, getFilterTypeName, getListQueryFileName, getListQueryHookName, getOrderByTypeName, getPrimaryKeyInfo, getSingleQueryFileName, getSingleQueryHookName, getSingleRowQueryName, getTableNames, hasValidPrimaryKey, lcFirst, ucFirst, } from './utils';
12
+ import { getAllRowsQueryName, getConditionTypeName, getFilterTypeName, getListQueryFileName, getListQueryHookName, getOrderByTypeName, getPrimaryKeyInfo, getSingleQueryFileName, getSingleQueryHookName, getSingleRowQueryName, getTableNames, hasValidPrimaryKey, lcFirst, ucFirst, } from './utils';
13
13
  export function generateListQueryHook(table, options = {}) {
14
- const { reactQueryEnabled = true, useCentralizedKeys = true, hasRelationships = false, } = options;
14
+ const { reactQueryEnabled = true, useCentralizedKeys = true, hasRelationships = false, condition: conditionEnabled = true, } = options;
15
15
  const { typeName, pluralName, singularName } = getTableNames(table);
16
16
  const hookName = getListQueryHookName(table);
17
17
  const queryName = getAllRowsQueryName(table);
18
18
  const filterTypeName = getFilterTypeName(table);
19
19
  const orderByTypeName = getOrderByTypeName(table);
20
+ const conditionTypeName = conditionEnabled ? getConditionTypeName(table) : undefined;
20
21
  const keysName = `${lcFirst(typeName)}Keys`;
21
22
  const scopeTypeName = `${typeName}Scope`;
22
23
  const selectTypeName = `${typeName}Select`;
@@ -37,7 +38,10 @@ export function generateListQueryHook(table, options = {}) {
37
38
  statements.push(createImportDeclaration('../query-keys', [scopeTypeName], true));
38
39
  }
39
40
  }
40
- statements.push(createImportDeclaration('../../orm/input-types', [selectTypeName, relationTypeName, filterTypeName, orderByTypeName], true));
41
+ const inputTypeImports = [selectTypeName, relationTypeName, filterTypeName, orderByTypeName];
42
+ if (conditionTypeName)
43
+ inputTypeImports.push(conditionTypeName);
44
+ statements.push(createImportDeclaration('../../orm/input-types', inputTypeImports, true));
41
45
  statements.push(createImportDeclaration('../../orm/select-types', [
42
46
  'FindManyArgs',
43
47
  'InferSelectResult',
@@ -45,7 +49,10 @@ export function generateListQueryHook(table, options = {}) {
45
49
  'HookStrictSelect',
46
50
  ], true));
47
51
  // Re-exports
48
- statements.push(createTypeReExport([selectTypeName, relationTypeName, filterTypeName, orderByTypeName], '../../orm/input-types'));
52
+ const reExportTypes = [selectTypeName, relationTypeName, filterTypeName, orderByTypeName];
53
+ if (conditionTypeName)
54
+ reExportTypes.push(conditionTypeName);
55
+ statements.push(createTypeReExport(reExportTypes, '../../orm/input-types'));
49
56
  // Query key
50
57
  if (useCentralizedKeys) {
51
58
  const keyDecl = t.exportNamedDeclaration(t.variableDeclaration('const', [
@@ -57,12 +64,14 @@ export function generateListQueryHook(table, options = {}) {
57
64
  statements.push(keyDecl);
58
65
  }
59
66
  else {
67
+ const findManyKeyTypeArgs = [
68
+ t.tsUnknownKeyword(),
69
+ typeRef(filterTypeName),
70
+ conditionTypeName ? typeRef(conditionTypeName) : t.tsNeverKeyword(),
71
+ typeRef(orderByTypeName),
72
+ ];
60
73
  const keyFn = t.arrowFunctionExpression([
61
- createFunctionParam('variables', typeRef('FindManyArgs', [
62
- t.tsUnknownKeyword(),
63
- typeRef(filterTypeName),
64
- typeRef(orderByTypeName),
65
- ]), true),
74
+ createFunctionParam('variables', typeRef('FindManyArgs', findManyKeyTypeArgs), true),
66
75
  ], asConst(t.arrayExpression([
67
76
  t.stringLiteral(typeName.toLowerCase()),
68
77
  t.stringLiteral('list'),
@@ -61,6 +61,12 @@ const FILTER_CONFIGS = [
61
61
  operators: ['equality', 'distinct', 'inArray', 'comparison', 'inet'],
62
62
  },
63
63
  { name: 'FullTextFilter', tsType: 'string', operators: ['fulltext'] },
64
+ // Vector filter (for pgvector embedding columns)
65
+ {
66
+ name: 'VectorFilter',
67
+ tsType: 'number[]',
68
+ operators: ['equality', 'distinct'],
69
+ },
64
70
  // List filters
65
71
  {
66
72
  name: 'StringListFilter',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-codegen",
3
- "version": "4.14.1",
3
+ "version": "4.14.3",
4
4
  "description": "GraphQL SDK generator for Constructive databases with React Query hooks",
5
5
  "keywords": [
6
6
  "graphql",
@@ -101,5 +101,5 @@
101
101
  "tsx": "^4.21.0",
102
102
  "typescript": "^5.9.3"
103
103
  },
104
- "gitHead": "64ef59e5114d52bc897c7e9ef92d35ca6525f12f"
104
+ "gitHead": "edb69fc817642476636394a89b47293b6a0c7c43"
105
105
  }