Skip to content

Commit 815edac

Browse files
committed
fix(codegen): align runtime exports and generated clients
1 parent d0fb96a commit 815edac

228 files changed

Lines changed: 703 additions & 429 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

graphql/codegen/src/__tests__/codegen/__snapshots__/react-query-hooks.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ export async function fetchUserQuery<S extends UserSelect>(params: {
18431843
export async function fetchUserQuery(params: {
18441844
id: string;
18451845
selection: SelectionConfig<UserSelect>;
1846-
}) {
1846+
}): Promise<any> {
18471847
const args = buildSelectionArgs<UserSelect>(params.selection);
18481848
return getClient().user.findOne({
18491849
id: params.id,
@@ -1975,7 +1975,7 @@ export async function fetchPostQuery<S extends PostSelect>(params: {
19751975
export async function fetchPostQuery(params: {
19761976
id: string;
19771977
selection: SelectionConfig<PostSelect>;
1978-
}) {
1978+
}): Promise<any> {
19791979
const args = buildSelectionArgs<PostSelect>(params.selection);
19801980
return getClient().post.findOne({
19811981
id: params.id,
@@ -2094,7 +2094,7 @@ export async function fetchUserQuery<S extends UserSelect>(params: {
20942094
export async function fetchUserQuery(params: {
20952095
id: string;
20962096
selection: SelectionConfig<UserSelect>;
2097-
}) {
2097+
}): Promise<any> {
20982098
const args = buildSelectionArgs<UserSelect>(params.selection);
20992099
return getClient().user.findOne({
21002100
id: params.id,

graphql/codegen/src/core/codegen/orm/client-generator.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,6 @@ export function generateCreateClientFile(
216216
// Re-export all models
217217
statements.push(t.exportAllDeclaration(t.stringLiteral('./models')));
218218

219-
// Re-export NodeHttpAdapter when enabled (for use in any Node.js application)
220-
if (options?.nodeHttpAdapter) {
221-
statements.push(
222-
t.exportNamedDeclaration(
223-
null,
224-
[
225-
t.exportSpecifier(
226-
t.identifier('NodeHttpAdapter'),
227-
t.identifier('NodeHttpAdapter'),
228-
),
229-
],
230-
t.stringLiteral('./node-fetch'),
231-
),
232-
);
233-
}
234-
235219
// Re-export custom operations
236220
if (hasCustomQueries) {
237221
statements.push(

graphql/codegen/src/core/codegen/queries.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ export function generateSingleQueryHook(
890890
null,
891891
[createFunctionParam('params', t.tsTypeLiteral(fImplProps))],
892892
fBody,
893+
typeRef('Promise', [t.tsAnyKeyword()]),
893894
),
894895
);
895896
}

graphql/query/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
"main": "index.js",
77
"module": "esm/index.js",
88
"types": "index.d.ts",
9+
"exports": {
10+
".": {
11+
"types": "./index.d.ts",
12+
"import": "./esm/index.js",
13+
"require": "./index.js"
14+
},
15+
"./runtime": {
16+
"types": "./runtime/index.d.ts",
17+
"import": "./esm/runtime/index.js",
18+
"require": "./runtime/index.js"
19+
}
20+
},
921
"homepage": "https://github.com/constructive-io/constructive",
1022
"license": "MIT",
1123
"publishConfig": {

graphql/query/src/runtime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ export { parseType, print } from '@0no-co/graphql.web';
2424
export type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-types';
2525

2626
// Isomorphic fetch with *.localhost DNS + Host header fix for Node.js
27-
export { createFetch } from './localhost-fetch';
28-
export type { FetchFunction } from './localhost-fetch';
27+
export { createFetch } from './localhost-fetch.js';
28+
export type { FetchFunction } from './localhost-fetch.js';

graphql/query/src/runtime/localhost-fetch.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
export type FetchFunction = typeof globalThis.fetch;
16+
type NodeModuleLoader = (id: string) => unknown;
1617

1718
export function isLocalhostSubdomain(hostname: string): boolean {
1819
return hostname.endsWith('.localhost') && hostname !== 'localhost';
@@ -106,6 +107,17 @@ function buildNodeFetch(
106107

107108
let _fetch: FetchFunction | undefined;
108109

110+
function getNodeModuleLoader(): NodeModuleLoader | undefined {
111+
try {
112+
// Keep node:http / node:https out of browser bundle static analysis.
113+
return Function(
114+
'return typeof require !== "undefined" ? require : undefined',
115+
)() as NodeModuleLoader | undefined;
116+
} catch {
117+
return undefined;
118+
}
119+
}
120+
109121
/**
110122
* Create an isomorphic fetch function.
111123
*
@@ -122,12 +134,13 @@ export function createFetch(): FetchFunction {
122134

123135
if (typeof process !== 'undefined' && process.versions?.node) {
124136
try {
125-
// eslint-disable-next-line @typescript-eslint/no-require-imports
126-
const http = require('node:http');
127-
// eslint-disable-next-line @typescript-eslint/no-require-imports
128-
const https = require('node:https');
129-
_fetch = buildNodeFetch(http, https);
130-
return _fetch;
137+
const nodeRequire = getNodeModuleLoader();
138+
if (nodeRequire) {
139+
const http = nodeRequire('node:' + 'http') as typeof import('node:http');
140+
const https = nodeRequire('node:' + 'https') as typeof import('node:https');
141+
_fetch = buildNodeFetch(http, https);
142+
return _fetch;
143+
}
131144
} catch {
132145
// node:http unavailable — fall through
133146
}

sdk/constructive-cli/src/admin/cli/commands/app-limit-event.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const fieldSchema: FieldSchema = {
2727
reason: 'string',
2828
};
2929
const usage =
30-
'\napp-limit-event <command>\n\nCommands:\n list List appLimitEvent records\n find-first Find first matching appLimitEvent record\n create Create a new appLimitEvent\n\nList Options:\n --limit <n> Max number of records to return (forward pagination)\n --last <n> Number of records from the end (backward pagination)\n --after <cursor> Cursor for forward pagination\n --before <cursor> Cursor for backward pagination\n --offset <n> Number of records to skip\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.name.equalTo foo)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\nFind-First Options:\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.status.equalTo active)\n --condition.<f>.<op> Condition filter (dot-notation)\n\n --help, -h Show this help message\n';
30+
'\napp-limit-event <command>\n\nCommands:\n list List appLimitEvent records\n find-first Find first matching appLimitEvent record\n create Create a new appLimitEvent\n\nList Options:\n --limit <n> Max number of records to return (forward pagination)\n --last <n> Number of records from the end (backward pagination)\n --after <cursor> Cursor for forward pagination\n --before <cursor> Cursor for backward pagination\n --offset <n> Number of records to skip\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.name.equalTo foo)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\nFind-First Options:\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.status.equalTo active)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\n --help, -h Show this help message\n';
3131
export default async (
3232
argv: Partial<Record<string, unknown>>,
3333
prompter: Inquirerer,
@@ -111,7 +111,7 @@ async function handleFindFirst(argv: Partial<Record<string, unknown>>, _prompter
111111
reason: true,
112112
};
113113
const findFirstArgs = parseFindFirstArgs<
114-
FindFirstArgs<AppLimitEventSelect, AppLimitEventFilter> & {
114+
FindFirstArgs<AppLimitEventSelect, AppLimitEventFilter, AppLimitEventOrderBy> & {
115115
select: AppLimitEventSelect;
116116
}
117117
>(argv, defaultSelect);

sdk/constructive-cli/src/admin/cli/commands/org-limit-aggregate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const fieldSchema: FieldSchema = {
2626
windowDuration: 'string',
2727
};
2828
const usage =
29-
'\norg-limit-aggregate <command>\n\nCommands:\n list List orgLimitAggregate records\n find-first Find first matching orgLimitAggregate record\n get Get a orgLimitAggregate by ID\n create Create a new orgLimitAggregate\n update Update an existing orgLimitAggregate\n delete Delete a orgLimitAggregate\n\nList Options:\n --limit <n> Max number of records to return (forward pagination)\n --last <n> Number of records from the end (backward pagination)\n --after <cursor> Cursor for forward pagination\n --before <cursor> Cursor for backward pagination\n --offset <n> Number of records to skip\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.name.equalTo foo)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\nFind-First Options:\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.status.equalTo active)\n --condition.<f>.<op> Condition filter (dot-notation)\n\n --help, -h Show this help message\n';
29+
'\norg-limit-aggregate <command>\n\nCommands:\n list List orgLimitAggregate records\n find-first Find first matching orgLimitAggregate record\n get Get a orgLimitAggregate by ID\n create Create a new orgLimitAggregate\n update Update an existing orgLimitAggregate\n delete Delete a orgLimitAggregate\n\nList Options:\n --limit <n> Max number of records to return (forward pagination)\n --last <n> Number of records from the end (backward pagination)\n --after <cursor> Cursor for forward pagination\n --before <cursor> Cursor for backward pagination\n --offset <n> Number of records to skip\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.name.equalTo foo)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\nFind-First Options:\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.status.equalTo active)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\n --help, -h Show this help message\n';
3030
export default async (
3131
argv: Partial<Record<string, unknown>>,
3232
prompter: Inquirerer,
@@ -114,7 +114,7 @@ async function handleFindFirst(argv: Partial<Record<string, unknown>>, _prompter
114114
windowDuration: true,
115115
};
116116
const findFirstArgs = parseFindFirstArgs<
117-
FindFirstArgs<OrgLimitAggregateSelect, OrgLimitAggregateFilter> & {
117+
FindFirstArgs<OrgLimitAggregateSelect, OrgLimitAggregateFilter, OrgLimitAggregateOrderBy> & {
118118
select: OrgLimitAggregateSelect;
119119
}
120120
>(argv, defaultSelect);

sdk/constructive-cli/src/admin/cli/commands/org-limit-event.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const fieldSchema: FieldSchema = {
2727
reason: 'string',
2828
};
2929
const usage =
30-
'\norg-limit-event <command>\n\nCommands:\n list List orgLimitEvent records\n find-first Find first matching orgLimitEvent record\n create Create a new orgLimitEvent\n\nList Options:\n --limit <n> Max number of records to return (forward pagination)\n --last <n> Number of records from the end (backward pagination)\n --after <cursor> Cursor for forward pagination\n --before <cursor> Cursor for backward pagination\n --offset <n> Number of records to skip\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.name.equalTo foo)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\nFind-First Options:\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.status.equalTo active)\n --condition.<f>.<op> Condition filter (dot-notation)\n\n --help, -h Show this help message\n';
30+
'\norg-limit-event <command>\n\nCommands:\n list List orgLimitEvent records\n find-first Find first matching orgLimitEvent record\n create Create a new orgLimitEvent\n\nList Options:\n --limit <n> Max number of records to return (forward pagination)\n --last <n> Number of records from the end (backward pagination)\n --after <cursor> Cursor for forward pagination\n --before <cursor> Cursor for backward pagination\n --offset <n> Number of records to skip\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.name.equalTo foo)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\nFind-First Options:\n --select <fields> Comma-separated list of fields to return\n --where.<field>.<op> Filter (dot-notation, e.g. --where.status.equalTo active)\n --condition.<f>.<op> Condition filter (dot-notation)\n --orderBy <values> Comma-separated ordering values (e.g. NAME_ASC,CREATED_AT_DESC)\n\n --help, -h Show this help message\n';
3131
export default async (
3232
argv: Partial<Record<string, unknown>>,
3333
prompter: Inquirerer,
@@ -111,7 +111,7 @@ async function handleFindFirst(argv: Partial<Record<string, unknown>>, _prompter
111111
reason: true,
112112
};
113113
const findFirstArgs = parseFindFirstArgs<
114-
FindFirstArgs<OrgLimitEventSelect, OrgLimitEventFilter> & {
114+
FindFirstArgs<OrgLimitEventSelect, OrgLimitEventFilter, OrgLimitEventOrderBy> & {
115115
select: OrgLimitEventSelect;
116116
}
117117
>(argv, defaultSelect);

sdk/constructive-cli/src/admin/orm/models/appLimitEvent.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,38 @@ export class AppLimitEventModel {
7070
});
7171
}
7272
findFirst<S extends AppLimitEventSelect>(
73-
args: FindFirstArgs<S, AppLimitEventFilter> & {
73+
args: FindFirstArgs<S, AppLimitEventFilter, AppLimitEventOrderBy> & {
7474
select: S;
7575
} & StrictSelect<S, AppLimitEventSelect>
7676
): QueryBuilder<{
77-
appLimitEvents: {
78-
nodes: InferSelectResult<AppLimitEventWithRelations, S>[];
79-
};
77+
appLimitEvent: InferSelectResult<AppLimitEventWithRelations, S> | null;
8078
}> {
8179
const { document, variables } = buildFindFirstDocument(
8280
'AppLimitEvent',
8381
'appLimitEvents',
8482
args.select,
8583
{
8684
where: args?.where,
85+
orderBy: args?.orderBy as string[] | undefined,
8786
},
8887
'AppLimitEventFilter',
88+
'AppLimitEventOrderBy',
8989
connectionFieldsMap
9090
);
9191
return new QueryBuilder({
9292
client: this.client,
9393
operation: 'query',
9494
operationName: 'AppLimitEvent',
95-
fieldName: 'appLimitEvents',
95+
fieldName: 'appLimitEvent',
9696
document,
9797
variables,
98+
transform: (data: {
99+
appLimitEvents?: {
100+
nodes?: InferSelectResult<AppLimitEventWithRelations, S>[];
101+
};
102+
}) => ({
103+
appLimitEvent: data.appLimitEvents?.nodes?.[0] ?? null,
104+
}),
98105
});
99106
}
100107
create<S extends AppLimitEventSelect>(

0 commit comments

Comments
 (0)