Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions graphql/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@constructive-io/graphql-types": "workspace:^",
"@inquirerer/utils": "^3.2.0",
"ajv": "^8.17.1",
"deepmerge": "^4.3.1",
"find-and-require-package-json": "^0.9.0",
"gql-ast": "workspace:^",
"graphql": "15.10.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('config resolution', () => {
expect(resolved.output).toBe(DEFAULT_CONFIG.output);
expect(resolved.tables.include).toEqual(DEFAULT_CONFIG.tables.include);
expect(resolved.queries.exclude).toEqual(DEFAULT_CONFIG.queries.exclude);
expect(resolved.queries.systemExclude).toEqual(DEFAULT_CONFIG.queries.systemExclude);
});

it('merges nested config values with overrides', () => {
Expand Down
2 changes: 1 addition & 1 deletion graphql/codegen/src/cli/codegen/orm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function generateOrm(options: GenerateOrmOptions): GenerateOrmResult {
const { tables, customOperations, config } = options;
const files: GeneratedFile[] = [];

const useSharedTypes = config.orm?.useSharedTypes ?? true;
const useSharedTypes = config.orm.useSharedTypes;
const hasCustomQueries = (customOperations?.queries.length ?? 0) > 0;
const hasCustomMutations = (customOperations?.mutations.length ?? 0) > 0;
const typeRegistry = customOperations?.typeRegistry;
Expand Down
10 changes: 5 additions & 5 deletions graphql/codegen/src/cli/commands/generate-orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { runCodegenPipeline, validateTablesFound } from './shared';
import { findConfigFile, loadConfigFile } from './init';
import { writeGeneratedFiles } from './generate';
import { generateOrm } from '../codegen/orm';
import { generateOrm as generateOrmFiles } from '../codegen/orm';

export interface GenerateOrmOptions {
/** Path to config file */
Expand Down Expand Up @@ -67,9 +67,9 @@ export interface GenerateOrmResult {
}

/**
* Execute the generate-orm command
* Execute the generate-orm command (generates ORM client)
*/
export async function generateOrmCommand(
export async function generateOrm(
options: GenerateOrmOptions = {}
): Promise<GenerateOrmResult> {
if (options.verbose) {
Expand Down Expand Up @@ -138,7 +138,7 @@ async function generateOrmForTarget(
isMultiTarget: boolean
): Promise<GenerateOrmTargetResult> {
const config = target.config;
const outputDir = options.output || config.orm?.output || './generated/orm';
const outputDir = options.output || config.orm.output;
const prefix = isMultiTarget ? `[${target.name}] ` : '';
const log = options.verbose
? (message: string) => console.log(`${prefix}${message}`)
Expand Down Expand Up @@ -211,7 +211,7 @@ async function generateOrmForTarget(

// 4. Generate ORM code
console.log(`${prefix}Generating code...`);
const { files: generatedFiles, stats: genStats } = generateOrm({
const { files: generatedFiles, stats: genStats } = generateOrmFiles({
tables,
customOperations: {
queries: customOperations.queries,
Expand Down
4 changes: 2 additions & 2 deletions graphql/codegen/src/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export interface GenerateResult {
}

/**
* Execute the generate command
* Execute the generate command (generates React Query SDK)
*/
export async function generateCommand(
export async function generateReactQuery(
options: GenerateOptions = {}
): Promise<GenerateResult> {
if (options.verbose) {
Expand Down
4 changes: 2 additions & 2 deletions graphql/codegen/src/cli/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
export { initCommand, findConfigFile, loadConfigFile } from './init';
export type { InitOptions, InitResult } from './init';

export { generateCommand } from './generate';
export { generateReactQuery } from './generate';
export type { GenerateOptions, GenerateResult, GenerateTargetResult } from './generate';

export { generateOrmCommand } from './generate-orm';
export { generateOrm } from './generate-orm';
export type { GenerateOrmOptions, GenerateOrmResult, GenerateOrmTargetResult } from './generate-orm';
13 changes: 8 additions & 5 deletions graphql/codegen/src/cli/commands/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ export async function runCodegenPipeline(
const totalTables = tables.length;
log(` Found ${totalTables} tables`);

// 3. Filter tables by config
tables = filterTables(tables, config.tables.include, config.tables.exclude);
// 3. Filter tables by config (combine exclude and systemExclude)
tables = filterTables(tables, config.tables.include, [
...config.tables.exclude,
...config.tables.systemExclude,
]);
const filteredTables = tables.length;
log(` After filtering: ${filteredTables} tables`);

Expand All @@ -138,16 +141,16 @@ export async function runCodegenPipeline(
let customMutations: CleanOperation[] = [];

if (!skipCustomOperations) {
// Filter by config include/exclude
// Filter by config include/exclude (combine exclude and systemExclude)
const filteredQueries = filterOperations(
allQueries,
config.queries.include,
config.queries.exclude
[...config.queries.exclude, ...config.queries.systemExclude]
);
const filteredMutations = filterOperations(
allMutations,
config.mutations.include,
config.mutations.exclude
[...config.mutations.exclude, ...config.mutations.systemExclude]
);

log(
Expand Down
8 changes: 4 additions & 4 deletions graphql/codegen/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { CLI, CLIOptions, Inquirerer, ParsedArgs, cliExitWithError, extractFirst, getPackageJson } from 'inquirerer';

import { initCommand, findConfigFile, loadConfigFile } from './commands/init';
import { generateCommand } from './commands/generate';
import { generateOrmCommand } from './commands/generate-orm';
import { generateReactQuery } from './commands/generate';
import { generateOrm } from './commands/generate-orm';
import { startWatch } from './watch';
import {
isMultiConfig,
Expand Down Expand Up @@ -312,7 +312,7 @@ async function handleGenerate(argv: Partial<ParsedArgs>): Promise<void> {
return;
}

const result = await generateCommand({
const result = await generateReactQuery({
config,
target,
endpoint,
Expand Down Expand Up @@ -444,7 +444,7 @@ async function handleGenerateOrm(argv: Partial<ParsedArgs>): Promise<void> {
return;
}

const result = await generateOrmCommand({
const result = await generateOrm({
config,
target,
endpoint,
Expand Down
10 changes: 5 additions & 5 deletions graphql/codegen/src/cli/watch/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import type { ResolvedConfig } from '../../types/config';
import type { GeneratorType, WatchOptions, PollEvent } from './types';
import { SchemaPoller } from './poller';
import { debounce } from './debounce';
import { generateCommand, type GenerateResult } from '../commands/generate';
import { generateReactQuery, type GenerateResult } from '../commands/generate';
import {
generateOrmCommand,
generateOrm,
type GenerateOrmResult,
} from '../commands/generate-orm';

Expand Down Expand Up @@ -195,7 +195,7 @@ export class WatchOrchestrator {
let result: GenerateResult | GenerateOrmResult;

if (this.options.generatorType === 'generate') {
result = await generateCommand({
result = await generateReactQuery({
config: this.options.configPath,
target: this.options.target,
endpoint: this.options.config.endpoint,
Expand All @@ -205,11 +205,11 @@ export class WatchOrchestrator {
skipCustomOperations: this.options.skipCustomOperations,
});
} else {
result = await generateOrmCommand({
result = await generateOrm({
config: this.options.configPath,
target: this.options.target,
endpoint: this.options.config.endpoint,
output: this.options.outputDir ?? this.options.config.orm?.output,
output: this.options.outputDir ?? this.options.config.orm.output,
authorization: this.options.authorization,
verbose: this.watchOptions.verbose,
skipCustomOperations: this.options.skipCustomOperations,
Expand Down
4 changes: 2 additions & 2 deletions graphql/codegen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export { defineConfig } from './types/config';

// CLI command exports (for packages/cli consumption)
export {
generateCommand,
generateOrmCommand,
generateReactQuery,
generateOrm,
findConfigFile,
loadConfigFile,
} from './cli/commands';
Expand Down
Loading