@constructive-io/graphql-codegen 2.22.1 → 2.23.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.
Files changed (99) hide show
  1. package/cli/codegen/barrel.d.ts +5 -1
  2. package/cli/codegen/barrel.js +13 -11
  3. package/cli/codegen/index.d.ts +3 -3
  4. package/cli/codegen/index.js +15 -9
  5. package/cli/codegen/orm/client-generator.js +3 -2
  6. package/cli/codegen/orm/custom-ops-generator.js +17 -4
  7. package/cli/codegen/orm/input-types-generator.js +129 -18
  8. package/cli/codegen/orm/model-generator.js +2 -1
  9. package/cli/codegen/orm/query-builder.d.ts +1 -1
  10. package/cli/codegen/orm/query-builder.js +2 -2
  11. package/cli/codegen/schema-types-generator.js +5 -5
  12. package/cli/codegen/utils.d.ts +6 -1
  13. package/cli/codegen/utils.js +23 -8
  14. package/cli/commands/generate-orm.d.ts +5 -3
  15. package/cli/commands/generate-orm.js +65 -84
  16. package/cli/commands/generate.d.ts +2 -0
  17. package/cli/commands/generate.js +66 -87
  18. package/cli/commands/shared.d.ts +74 -0
  19. package/cli/commands/shared.js +88 -0
  20. package/cli/index.js +75 -45
  21. package/cli/introspect/index.d.ts +8 -5
  22. package/cli/introspect/index.js +19 -7
  23. package/cli/introspect/infer-tables.d.ts +51 -0
  24. package/cli/introspect/infer-tables.js +550 -0
  25. package/cli/introspect/source/endpoint.d.ts +34 -0
  26. package/cli/introspect/source/endpoint.js +35 -0
  27. package/cli/introspect/source/file.d.ts +20 -0
  28. package/cli/introspect/source/file.js +103 -0
  29. package/cli/introspect/source/index.d.ts +48 -0
  30. package/cli/introspect/source/index.js +72 -0
  31. package/cli/introspect/source/types.d.ts +58 -0
  32. package/cli/introspect/source/types.js +27 -0
  33. package/cli/introspect/transform.d.ts +5 -6
  34. package/cli/introspect/transform.js +0 -173
  35. package/cli/watch/cache.d.ts +3 -4
  36. package/cli/watch/cache.js +6 -10
  37. package/cli/watch/poller.d.ts +1 -2
  38. package/cli/watch/poller.js +27 -45
  39. package/cli/watch/types.d.ts +0 -3
  40. package/core/ast.js +4 -4
  41. package/core/query-builder.js +12 -12
  42. package/esm/cli/codegen/barrel.d.ts +5 -1
  43. package/esm/cli/codegen/barrel.js +13 -11
  44. package/esm/cli/codegen/index.d.ts +3 -3
  45. package/esm/cli/codegen/index.js +18 -12
  46. package/esm/cli/codegen/orm/client-generator.js +3 -2
  47. package/esm/cli/codegen/orm/custom-ops-generator.js +18 -5
  48. package/esm/cli/codegen/orm/input-types-generator.js +130 -19
  49. package/esm/cli/codegen/orm/model-generator.js +3 -2
  50. package/esm/cli/codegen/orm/query-builder.d.ts +1 -1
  51. package/esm/cli/codegen/orm/query-builder.js +2 -2
  52. package/esm/cli/codegen/schema-types-generator.js +6 -6
  53. package/esm/cli/codegen/utils.d.ts +6 -1
  54. package/esm/cli/codegen/utils.js +22 -8
  55. package/esm/cli/commands/generate-orm.d.ts +5 -3
  56. package/esm/cli/commands/generate-orm.js +65 -84
  57. package/esm/cli/commands/generate.d.ts +2 -0
  58. package/esm/cli/commands/generate.js +66 -87
  59. package/esm/cli/commands/shared.d.ts +74 -0
  60. package/esm/cli/commands/shared.js +84 -0
  61. package/esm/cli/index.js +76 -46
  62. package/esm/cli/introspect/index.d.ts +8 -5
  63. package/esm/cli/introspect/index.js +10 -3
  64. package/esm/cli/introspect/infer-tables.d.ts +51 -0
  65. package/esm/cli/introspect/infer-tables.js +547 -0
  66. package/esm/cli/introspect/source/endpoint.d.ts +34 -0
  67. package/esm/cli/introspect/source/endpoint.js +31 -0
  68. package/esm/cli/introspect/source/file.d.ts +20 -0
  69. package/esm/cli/introspect/source/file.js +66 -0
  70. package/esm/cli/introspect/source/index.d.ts +48 -0
  71. package/esm/cli/introspect/source/index.js +54 -0
  72. package/esm/cli/introspect/source/types.d.ts +58 -0
  73. package/esm/cli/introspect/source/types.js +23 -0
  74. package/esm/cli/introspect/transform.d.ts +5 -6
  75. package/esm/cli/introspect/transform.js +0 -172
  76. package/esm/cli/watch/cache.d.ts +3 -4
  77. package/esm/cli/watch/cache.js +7 -11
  78. package/esm/cli/watch/poller.d.ts +1 -2
  79. package/esm/cli/watch/poller.js +28 -46
  80. package/esm/cli/watch/types.d.ts +0 -3
  81. package/esm/core/ast.js +4 -4
  82. package/esm/core/query-builder.js +12 -12
  83. package/esm/generators/mutations.js +3 -3
  84. package/esm/generators/select.js +7 -7
  85. package/esm/types/config.d.ts +21 -5
  86. package/esm/types/config.js +2 -1
  87. package/generators/mutations.js +3 -3
  88. package/generators/select.js +7 -7
  89. package/package.json +5 -3
  90. package/types/config.d.ts +21 -5
  91. package/types/config.js +2 -1
  92. package/cli/introspect/fetch-meta.d.ts +0 -31
  93. package/cli/introspect/fetch-meta.js +0 -108
  94. package/cli/introspect/meta-query.d.ts +0 -111
  95. package/cli/introspect/meta-query.js +0 -191
  96. package/esm/cli/introspect/fetch-meta.d.ts +0 -31
  97. package/esm/cli/introspect/fetch-meta.js +0 -104
  98. package/esm/cli/introspect/meta-query.d.ts +0 -111
  99. package/esm/cli/introspect/meta-query.js +0 -188
@@ -1,111 +0,0 @@
1
- /**
2
- * The _meta GraphQL query for introspecting PostGraphile schema
3
- * This query fetches all table metadata including fields, constraints, and relations
4
- */
5
- export declare const META_QUERY = "\nquery Meta {\n _meta {\n tables {\n name\n query {\n all\n create\n delete\n one\n update\n }\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n inflection {\n allRows\n allRowsSimple\n conditionType\n connection\n createField\n createInputType\n createPayloadType\n deleteByPrimaryKey\n deletePayloadType\n edge\n edgeField\n enumType\n filterType\n inputType\n orderByType\n patchField\n patchType\n tableFieldName\n tableType\n typeName\n updateByPrimaryKey\n updatePayloadType\n }\n primaryKeyConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n }\n uniqueConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n }\n foreignKeyConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n refFields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n refTable {\n name\n }\n }\n relations {\n belongsTo {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n references {\n name\n }\n type\n }\n hasOne {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n referencedBy {\n name\n }\n type\n }\n hasMany {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n referencedBy {\n name\n }\n type\n }\n manyToMany {\n fieldName\n junctionTable {\n name\n }\n rightTable {\n name\n }\n type\n }\n }\n }\n }\n}\n";
6
- /**
7
- * Types for the _meta query response
8
- */
9
- export interface MetaFieldType {
10
- gqlType: string;
11
- isArray: boolean;
12
- modifier: string | number | null;
13
- pgAlias: string | null;
14
- pgType: string | null;
15
- subtype: string | null;
16
- typmod: number | null;
17
- }
18
- export interface MetaField {
19
- name: string;
20
- type: MetaFieldType;
21
- }
22
- export interface MetaConstraint {
23
- name: string;
24
- fields: MetaField[];
25
- }
26
- export interface MetaForeignKeyConstraint extends MetaConstraint {
27
- refFields: MetaField[];
28
- refTable: {
29
- name: string;
30
- };
31
- }
32
- export interface MetaTableQuery {
33
- all: string;
34
- create: string;
35
- delete: string | null;
36
- one: string;
37
- update: string | null;
38
- }
39
- export interface MetaTableInflection {
40
- allRows: string;
41
- allRowsSimple: string;
42
- conditionType: string;
43
- connection: string;
44
- createField: string;
45
- createInputType: string;
46
- createPayloadType: string;
47
- deleteByPrimaryKey: string | null;
48
- deletePayloadType: string;
49
- edge: string;
50
- edgeField: string;
51
- enumType: string;
52
- filterType: string | null;
53
- inputType: string;
54
- orderByType: string;
55
- patchField: string;
56
- patchType: string | null;
57
- tableFieldName: string;
58
- tableType: string;
59
- typeName: string;
60
- updateByPrimaryKey: string | null;
61
- updatePayloadType: string | null;
62
- }
63
- export interface MetaBelongsToRelation {
64
- fieldName: string | null;
65
- isUnique: boolean;
66
- keys: MetaField[];
67
- references: {
68
- name: string;
69
- };
70
- type: string | null;
71
- }
72
- export interface MetaHasRelation {
73
- fieldName: string | null;
74
- isUnique: boolean;
75
- keys: MetaField[];
76
- referencedBy: {
77
- name: string;
78
- };
79
- type: string | null;
80
- }
81
- export interface MetaManyToManyRelation {
82
- fieldName: string | null;
83
- junctionTable: {
84
- name: string;
85
- };
86
- rightTable: {
87
- name: string;
88
- };
89
- type: string | null;
90
- }
91
- export interface MetaTableRelations {
92
- belongsTo: MetaBelongsToRelation[];
93
- hasOne: MetaHasRelation[];
94
- hasMany: MetaHasRelation[];
95
- manyToMany: MetaManyToManyRelation[];
96
- }
97
- export interface MetaTable {
98
- name: string;
99
- query: MetaTableQuery;
100
- fields: MetaField[];
101
- inflection: MetaTableInflection;
102
- primaryKeyConstraints: MetaConstraint[];
103
- uniqueConstraints: MetaConstraint[];
104
- foreignKeyConstraints: MetaForeignKeyConstraint[];
105
- relations: MetaTableRelations;
106
- }
107
- export interface MetaQueryResponse {
108
- _meta: {
109
- tables: MetaTable[];
110
- };
111
- }
@@ -1,191 +0,0 @@
1
- "use strict";
2
- /**
3
- * The _meta GraphQL query for introspecting PostGraphile schema
4
- * This query fetches all table metadata including fields, constraints, and relations
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.META_QUERY = void 0;
8
- exports.META_QUERY = `
9
- query Meta {
10
- _meta {
11
- tables {
12
- name
13
- query {
14
- all
15
- create
16
- delete
17
- one
18
- update
19
- }
20
- fields {
21
- name
22
- type {
23
- gqlType
24
- isArray
25
- modifier
26
- pgAlias
27
- pgType
28
- subtype
29
- typmod
30
- }
31
- }
32
- inflection {
33
- allRows
34
- allRowsSimple
35
- conditionType
36
- connection
37
- createField
38
- createInputType
39
- createPayloadType
40
- deleteByPrimaryKey
41
- deletePayloadType
42
- edge
43
- edgeField
44
- enumType
45
- filterType
46
- inputType
47
- orderByType
48
- patchField
49
- patchType
50
- tableFieldName
51
- tableType
52
- typeName
53
- updateByPrimaryKey
54
- updatePayloadType
55
- }
56
- primaryKeyConstraints {
57
- name
58
- fields {
59
- name
60
- type {
61
- gqlType
62
- isArray
63
- modifier
64
- pgAlias
65
- pgType
66
- subtype
67
- typmod
68
- }
69
- }
70
- }
71
- uniqueConstraints {
72
- name
73
- fields {
74
- name
75
- type {
76
- gqlType
77
- isArray
78
- modifier
79
- pgAlias
80
- pgType
81
- subtype
82
- typmod
83
- }
84
- }
85
- }
86
- foreignKeyConstraints {
87
- name
88
- fields {
89
- name
90
- type {
91
- gqlType
92
- isArray
93
- modifier
94
- pgAlias
95
- pgType
96
- subtype
97
- typmod
98
- }
99
- }
100
- refFields {
101
- name
102
- type {
103
- gqlType
104
- isArray
105
- modifier
106
- pgAlias
107
- pgType
108
- subtype
109
- typmod
110
- }
111
- }
112
- refTable {
113
- name
114
- }
115
- }
116
- relations {
117
- belongsTo {
118
- fieldName
119
- isUnique
120
- keys {
121
- name
122
- type {
123
- gqlType
124
- isArray
125
- modifier
126
- pgAlias
127
- pgType
128
- subtype
129
- typmod
130
- }
131
- }
132
- references {
133
- name
134
- }
135
- type
136
- }
137
- hasOne {
138
- fieldName
139
- isUnique
140
- keys {
141
- name
142
- type {
143
- gqlType
144
- isArray
145
- modifier
146
- pgAlias
147
- pgType
148
- subtype
149
- typmod
150
- }
151
- }
152
- referencedBy {
153
- name
154
- }
155
- type
156
- }
157
- hasMany {
158
- fieldName
159
- isUnique
160
- keys {
161
- name
162
- type {
163
- gqlType
164
- isArray
165
- modifier
166
- pgAlias
167
- pgType
168
- subtype
169
- typmod
170
- }
171
- }
172
- referencedBy {
173
- name
174
- }
175
- type
176
- }
177
- manyToMany {
178
- fieldName
179
- junctionTable {
180
- name
181
- }
182
- rightTable {
183
- name
184
- }
185
- type
186
- }
187
- }
188
- }
189
- }
190
- }
191
- `;
@@ -1,31 +0,0 @@
1
- /**
2
- * Fetch _meta query from a PostGraphile endpoint
3
- */
4
- import { type MetaQueryResponse } from './meta-query';
5
- export interface FetchMetaOptions {
6
- /** GraphQL endpoint URL */
7
- endpoint: string;
8
- /** Optional authorization header value (e.g., "Bearer token") */
9
- authorization?: string;
10
- /** Optional additional headers */
11
- headers?: Record<string, string>;
12
- /** Request timeout in milliseconds (default: 30000) */
13
- timeout?: number;
14
- }
15
- export interface FetchMetaResult {
16
- success: boolean;
17
- data?: MetaQueryResponse;
18
- error?: string;
19
- statusCode?: number;
20
- }
21
- /**
22
- * Fetch the _meta query from a PostGraphile endpoint
23
- */
24
- export declare function fetchMeta(options: FetchMetaOptions): Promise<FetchMetaResult>;
25
- /**
26
- * Validate that an endpoint URL is valid
27
- */
28
- export declare function validateEndpoint(endpoint: string): {
29
- valid: boolean;
30
- error?: string;
31
- };
@@ -1,104 +0,0 @@
1
- /**
2
- * Fetch _meta query from a PostGraphile endpoint
3
- */
4
- import { META_QUERY } from './meta-query';
5
- /**
6
- * Fetch the _meta query from a PostGraphile endpoint
7
- */
8
- export async function fetchMeta(options) {
9
- const { endpoint, authorization, headers = {}, timeout = 30000 } = options;
10
- // Build headers
11
- const requestHeaders = {
12
- 'Content-Type': 'application/json',
13
- Accept: 'application/json',
14
- ...headers,
15
- };
16
- if (authorization) {
17
- requestHeaders['Authorization'] = authorization;
18
- }
19
- // Create abort controller for timeout
20
- const controller = new AbortController();
21
- const timeoutId = setTimeout(() => controller.abort(), timeout);
22
- try {
23
- const response = await fetch(endpoint, {
24
- method: 'POST',
25
- headers: requestHeaders,
26
- body: JSON.stringify({
27
- query: META_QUERY,
28
- variables: {},
29
- }),
30
- signal: controller.signal,
31
- });
32
- clearTimeout(timeoutId);
33
- if (!response.ok) {
34
- return {
35
- success: false,
36
- error: `HTTP ${response.status}: ${response.statusText}`,
37
- statusCode: response.status,
38
- };
39
- }
40
- const json = (await response.json());
41
- // Check for GraphQL errors
42
- if (json.errors && json.errors.length > 0) {
43
- const errorMessages = json.errors.map((e) => e.message).join('; ');
44
- return {
45
- success: false,
46
- error: `GraphQL errors: ${errorMessages}`,
47
- statusCode: response.status,
48
- };
49
- }
50
- // Check if _meta is present
51
- if (!json.data?._meta) {
52
- return {
53
- success: false,
54
- error: 'No _meta field in response. Make sure the endpoint has the PostGraphile meta plugin installed.',
55
- statusCode: response.status,
56
- };
57
- }
58
- return {
59
- success: true,
60
- data: json.data,
61
- statusCode: response.status,
62
- };
63
- }
64
- catch (err) {
65
- clearTimeout(timeoutId);
66
- if (err instanceof Error) {
67
- if (err.name === 'AbortError') {
68
- return {
69
- success: false,
70
- error: `Request timeout after ${timeout}ms`,
71
- };
72
- }
73
- return {
74
- success: false,
75
- error: err.message,
76
- };
77
- }
78
- return {
79
- success: false,
80
- error: 'Unknown error occurred',
81
- };
82
- }
83
- }
84
- /**
85
- * Validate that an endpoint URL is valid
86
- */
87
- export function validateEndpoint(endpoint) {
88
- try {
89
- const url = new URL(endpoint);
90
- if (!['http:', 'https:'].includes(url.protocol)) {
91
- return {
92
- valid: false,
93
- error: 'Endpoint must use http or https protocol',
94
- };
95
- }
96
- return { valid: true };
97
- }
98
- catch {
99
- return {
100
- valid: false,
101
- error: 'Invalid URL format',
102
- };
103
- }
104
- }
@@ -1,111 +0,0 @@
1
- /**
2
- * The _meta GraphQL query for introspecting PostGraphile schema
3
- * This query fetches all table metadata including fields, constraints, and relations
4
- */
5
- export declare const META_QUERY = "\nquery Meta {\n _meta {\n tables {\n name\n query {\n all\n create\n delete\n one\n update\n }\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n inflection {\n allRows\n allRowsSimple\n conditionType\n connection\n createField\n createInputType\n createPayloadType\n deleteByPrimaryKey\n deletePayloadType\n edge\n edgeField\n enumType\n filterType\n inputType\n orderByType\n patchField\n patchType\n tableFieldName\n tableType\n typeName\n updateByPrimaryKey\n updatePayloadType\n }\n primaryKeyConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n }\n uniqueConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n }\n foreignKeyConstraints {\n name\n fields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n refFields {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n refTable {\n name\n }\n }\n relations {\n belongsTo {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n references {\n name\n }\n type\n }\n hasOne {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n referencedBy {\n name\n }\n type\n }\n hasMany {\n fieldName\n isUnique\n keys {\n name\n type {\n gqlType\n isArray\n modifier\n pgAlias\n pgType\n subtype\n typmod\n }\n }\n referencedBy {\n name\n }\n type\n }\n manyToMany {\n fieldName\n junctionTable {\n name\n }\n rightTable {\n name\n }\n type\n }\n }\n }\n }\n}\n";
6
- /**
7
- * Types for the _meta query response
8
- */
9
- export interface MetaFieldType {
10
- gqlType: string;
11
- isArray: boolean;
12
- modifier: string | number | null;
13
- pgAlias: string | null;
14
- pgType: string | null;
15
- subtype: string | null;
16
- typmod: number | null;
17
- }
18
- export interface MetaField {
19
- name: string;
20
- type: MetaFieldType;
21
- }
22
- export interface MetaConstraint {
23
- name: string;
24
- fields: MetaField[];
25
- }
26
- export interface MetaForeignKeyConstraint extends MetaConstraint {
27
- refFields: MetaField[];
28
- refTable: {
29
- name: string;
30
- };
31
- }
32
- export interface MetaTableQuery {
33
- all: string;
34
- create: string;
35
- delete: string | null;
36
- one: string;
37
- update: string | null;
38
- }
39
- export interface MetaTableInflection {
40
- allRows: string;
41
- allRowsSimple: string;
42
- conditionType: string;
43
- connection: string;
44
- createField: string;
45
- createInputType: string;
46
- createPayloadType: string;
47
- deleteByPrimaryKey: string | null;
48
- deletePayloadType: string;
49
- edge: string;
50
- edgeField: string;
51
- enumType: string;
52
- filterType: string | null;
53
- inputType: string;
54
- orderByType: string;
55
- patchField: string;
56
- patchType: string | null;
57
- tableFieldName: string;
58
- tableType: string;
59
- typeName: string;
60
- updateByPrimaryKey: string | null;
61
- updatePayloadType: string | null;
62
- }
63
- export interface MetaBelongsToRelation {
64
- fieldName: string | null;
65
- isUnique: boolean;
66
- keys: MetaField[];
67
- references: {
68
- name: string;
69
- };
70
- type: string | null;
71
- }
72
- export interface MetaHasRelation {
73
- fieldName: string | null;
74
- isUnique: boolean;
75
- keys: MetaField[];
76
- referencedBy: {
77
- name: string;
78
- };
79
- type: string | null;
80
- }
81
- export interface MetaManyToManyRelation {
82
- fieldName: string | null;
83
- junctionTable: {
84
- name: string;
85
- };
86
- rightTable: {
87
- name: string;
88
- };
89
- type: string | null;
90
- }
91
- export interface MetaTableRelations {
92
- belongsTo: MetaBelongsToRelation[];
93
- hasOne: MetaHasRelation[];
94
- hasMany: MetaHasRelation[];
95
- manyToMany: MetaManyToManyRelation[];
96
- }
97
- export interface MetaTable {
98
- name: string;
99
- query: MetaTableQuery;
100
- fields: MetaField[];
101
- inflection: MetaTableInflection;
102
- primaryKeyConstraints: MetaConstraint[];
103
- uniqueConstraints: MetaConstraint[];
104
- foreignKeyConstraints: MetaForeignKeyConstraint[];
105
- relations: MetaTableRelations;
106
- }
107
- export interface MetaQueryResponse {
108
- _meta: {
109
- tables: MetaTable[];
110
- };
111
- }