diff --git a/src/layers/2_generator/__snapshots__/files.test.ts.snap b/src/layers/2_generator/__snapshots__/files.test.ts.snap index b813e299d..c0dea2380 100644 --- a/src/layers/2_generator/__snapshots__/files.test.ts.snap +++ b/src/layers/2_generator/__snapshots__/files.test.ts.snap @@ -17,7 +17,7 @@ exports[`schema2 2`] = ` exports[`schema2 3`] = ` "export { create } from './Client.js' export { isError } from './Error.js' -export * as Select from './Select.js' +export { Select } from './Select.js' " `; @@ -52,106 +52,106 @@ import { Index } from './Index.js' import { createSelect } from '../../../../src/entrypoints/alpha/client.js' export const Select = createSelect('default') -// Root Types -// ---------- +// Buildtime +// --------- -export type Mutation<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< - $SelectionSet, - Index, - 'Mutation' -> +export namespace Select { + // Root Types + // ---------- -export type Query<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< - $SelectionSet, - Index, - 'Query' -> + export type Mutation<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< + $SelectionSet, + Index, + 'Mutation' + > -// Object Types -// ------------ + export type Query<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< + $SelectionSet, + Index, + 'Query' + > -export type Bar<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Bar'], - Index -> + // Object Types + // ------------ -export type DateObject1<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index> + export type Bar<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< + $SelectionSet, + Index['objects']['Bar'], + Index + > -export type DateObject2<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index> + export type DateObject1<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index> -export type ErrorOne<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ErrorOne'], Index> + export type DateObject2<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index> -export type ErrorTwo<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ErrorTwo'], Index> + export type ErrorOne<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ErrorOne'], Index> -export type Foo<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Foo'], - Index -> + export type ErrorTwo<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ErrorTwo'], Index> -export type Object1<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Object1'], - Index -> + export type Foo<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< + $SelectionSet, + Index['objects']['Foo'], + Index + > -export type Object1ImplementingInterface< - $SelectionSet extends SelectionSet.Object, -> = ResultSet.Object$<$SelectionSet, Index['objects']['Object1ImplementingInterface'], Index> + export type Object1<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['Object1'], Index> -export type Object2ImplementingInterface< - $SelectionSet extends SelectionSet.Object, -> = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index> + export type Object1ImplementingInterface< + $SelectionSet extends SelectionSet.Object, + > = ResultSet.Object$<$SelectionSet, Index['objects']['Object1ImplementingInterface'], Index> -export type ObjectNested<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index> + export type Object2ImplementingInterface< + $SelectionSet extends SelectionSet.Object, + > = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index> -export type ObjectUnion<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index> + export type ObjectNested<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index> -export type lowerCaseObject<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index> + export type ObjectUnion<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index> -export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index> + export type lowerCaseObject<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index> -// Union Types -// ----------- + export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index> -export type DateUnion<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< - $SelectionSet, - Index['unions']['DateUnion'], - Index -> + // Union Types + // ----------- -export type FooBarUnion<$SelectionSet extends SelectionSet.Union> = - ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index> + export type DateUnion<$SelectionSet extends SelectionSet.Union> = + ResultSet.Union<$SelectionSet, Index['unions']['DateUnion'], Index> -export type Result<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< - $SelectionSet, - Index['unions']['Result'], - Index -> + export type FooBarUnion<$SelectionSet extends SelectionSet.Union> = + ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index> -export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union> = - ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index> + export type Result<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< + $SelectionSet, + Index['unions']['Result'], + Index + > -// Interface Types -// --------------- + export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union> = + ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index> -export type DateInterface1<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index> + // Interface Types + // --------------- -export type Error<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['Error'], Index> + export type DateInterface1< + $SelectionSet extends SelectionSet.Interface, + > = ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index> -export type Interface<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['Interface'], Index> + export type Error<$SelectionSet extends SelectionSet.Interface> = + ResultSet.Interface<$SelectionSet, Index['interfaces']['Error'], Index> + + export type Interface<$SelectionSet extends SelectionSet.Interface> = + ResultSet.Interface<$SelectionSet, Index['interfaces']['Interface'], Index> +} " `; diff --git a/src/layers/2_generator/code/Select.ts b/src/layers/2_generator/code/Select.ts index 309abdd30..6164d5615 100644 --- a/src/layers/2_generator/code/Select.ts +++ b/src/layers/2_generator/code/Select.ts @@ -11,12 +11,16 @@ export const { generate: generateSelect, moduleName: moduleNameSelect } = create code.push(`import { SelectionSet, ResultSet } from '${config.libraryPaths.schema}'`) code.push(``) - code.push(title(`Runtime`)) - code.push(`import { createSelect } from '${config.libraryPaths.client}'`) - code.push(`export const Select = createSelect('default')`) - code.push(``) - - code.push(typeTitle(config, `Root`)) + code.push( + title(`Runtime`), + `import { createSelect } from '${config.libraryPaths.client}'`, + `export const Select = createSelect('default')`, + ``, + title(`Buildtime`), + ``, + `export namespace Select {`, + typeTitle(config, `Root`), + ) code.push(...config.typeMapByKind.GraphQLRootType.map((type) => { return `export type ${type.name}<$SelectionSet extends SelectionSet.Root> = ResultSet.Root<$SelectionSet, Index, '${type.name}'>\n` @@ -41,6 +45,8 @@ export const { generate: generateSelect, moduleName: moduleNameSelect } = create return `export type ${type.name}<$SelectionSet extends SelectionSet.Interface> = ResultSet.Interface<$SelectionSet, Index['interfaces']['${type.name}'], Index>\n` })) + code.push(`}`) // namespace Select + return code.join(`\n`) }, ) diff --git a/src/layers/2_generator/code/_.ts b/src/layers/2_generator/code/_.ts index a89c1da48..559325f77 100644 --- a/src/layers/2_generator/code/_.ts +++ b/src/layers/2_generator/code/_.ts @@ -8,7 +8,7 @@ export const { generate: generate_, moduleName: moduleName_ } = createCodeGenera (_config) => { const code: string[] = [] code.push( - `export * as Select from './${moduleNameSelect}.js'`, + `export { Select } from './${moduleNameSelect}.js'`, `export { isError } from './${moduleNameError}.js'`, `export { create } from './${moduleNameClient}.js'`, ) diff --git a/tests/_/schema/generated/Select.ts b/tests/_/schema/generated/Select.ts index 03e4f28ec..6216e0471 100644 --- a/tests/_/schema/generated/Select.ts +++ b/tests/_/schema/generated/Select.ts @@ -7,103 +7,103 @@ import { Index } from './Index.js' import { createSelect } from '../../../../src/entrypoints/alpha/client.js' export const Select = createSelect('default') -// Root Types -// ---------- +// Buildtime +// --------- -export type Mutation<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< - $SelectionSet, - Index, - 'Mutation' -> +export namespace Select { + // Root Types + // ---------- -export type Query<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< - $SelectionSet, - Index, - 'Query' -> + export type Mutation<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< + $SelectionSet, + Index, + 'Mutation' + > -// Object Types -// ------------ + export type Query<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< + $SelectionSet, + Index, + 'Query' + > -export type Bar<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Bar'], - Index -> + // Object Types + // ------------ -export type DateObject1<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index> + export type Bar<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< + $SelectionSet, + Index['objects']['Bar'], + Index + > -export type DateObject2<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index> + export type DateObject1<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index> -export type ErrorOne<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ErrorOne'], Index> + export type DateObject2<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index> -export type ErrorTwo<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ErrorTwo'], Index> + export type ErrorOne<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ErrorOne'], Index> -export type Foo<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Foo'], - Index -> + export type ErrorTwo<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ErrorTwo'], Index> -export type Object1<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< - $SelectionSet, - Index['objects']['Object1'], - Index -> + export type Foo<$SelectionSet extends SelectionSet.Object> = ResultSet.Object$< + $SelectionSet, + Index['objects']['Foo'], + Index + > -export type Object1ImplementingInterface< - $SelectionSet extends SelectionSet.Object, -> = ResultSet.Object$<$SelectionSet, Index['objects']['Object1ImplementingInterface'], Index> + export type Object1<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['Object1'], Index> -export type Object2ImplementingInterface< - $SelectionSet extends SelectionSet.Object, -> = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index> + export type Object1ImplementingInterface< + $SelectionSet extends SelectionSet.Object, + > = ResultSet.Object$<$SelectionSet, Index['objects']['Object1ImplementingInterface'], Index> -export type ObjectNested<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index> + export type Object2ImplementingInterface< + $SelectionSet extends SelectionSet.Object, + > = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index> -export type ObjectUnion<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index> + export type ObjectNested<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index> -export type lowerCaseObject<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index> + export type ObjectUnion<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index> -export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object> = - ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index> + export type lowerCaseObject<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index> -// Union Types -// ----------- + export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object> = + ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index> -export type DateUnion<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< - $SelectionSet, - Index['unions']['DateUnion'], - Index -> + // Union Types + // ----------- -export type FooBarUnion<$SelectionSet extends SelectionSet.Union> = - ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index> + export type DateUnion<$SelectionSet extends SelectionSet.Union> = + ResultSet.Union<$SelectionSet, Index['unions']['DateUnion'], Index> -export type Result<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< - $SelectionSet, - Index['unions']['Result'], - Index -> + export type FooBarUnion<$SelectionSet extends SelectionSet.Union> = + ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index> -export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union> = - ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index> + export type Result<$SelectionSet extends SelectionSet.Union> = ResultSet.Union< + $SelectionSet, + Index['unions']['Result'], + Index + > -// Interface Types -// --------------- + export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union> = + ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index> -export type DateInterface1<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index> + // Interface Types + // --------------- -export type Error<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['Error'], Index> + export type DateInterface1< + $SelectionSet extends SelectionSet.Interface, + > = ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index> -export type Interface<$SelectionSet extends SelectionSet.Interface> = - ResultSet.Interface<$SelectionSet, Index['interfaces']['Interface'], Index> + export type Error<$SelectionSet extends SelectionSet.Interface> = + ResultSet.Interface<$SelectionSet, Index['interfaces']['Error'], Index> + + export type Interface<$SelectionSet extends SelectionSet.Interface> = + ResultSet.Interface<$SelectionSet, Index['interfaces']['Interface'], Index> +} diff --git a/tests/_/schema/generated/_.ts b/tests/_/schema/generated/_.ts index f871bbefd..5e2498a39 100644 --- a/tests/_/schema/generated/_.ts +++ b/tests/_/schema/generated/_.ts @@ -1,3 +1,3 @@ export { create } from './Client.js' export { isError } from './Error.js' -export * as Select from './Select.js' +export { Select } from './Select.js' diff --git a/tests/_/schemaMutationOnly/generated/Select.ts b/tests/_/schemaMutationOnly/generated/Select.ts index f83a1a8b2..c663e3d6c 100644 --- a/tests/_/schemaMutationOnly/generated/Select.ts +++ b/tests/_/schemaMutationOnly/generated/Select.ts @@ -7,26 +7,31 @@ import { Index } from './Index.js' import { createSelect } from '../../../../src/entrypoints/alpha/client.js' export const Select = createSelect('default') -// Root Types -// ---------- +// Buildtime +// --------- -export type Mutation<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< - $SelectionSet, - Index, - 'Mutation' -> +export namespace Select { + // Root Types + // ---------- -// Object Types -// ------------ + export type Mutation<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< + $SelectionSet, + Index, + 'Mutation' + > -// -- None -- + // Object Types + // ------------ -// Union Types -// ----------- + // -- None -- -// -- None -- + // Union Types + // ----------- -// Interface Types -// --------------- + // -- None -- -// -- None -- + // Interface Types + // --------------- + + // -- None -- +} diff --git a/tests/_/schemaMutationOnly/generated/_.ts b/tests/_/schemaMutationOnly/generated/_.ts index f871bbefd..5e2498a39 100644 --- a/tests/_/schemaMutationOnly/generated/_.ts +++ b/tests/_/schemaMutationOnly/generated/_.ts @@ -1,3 +1,3 @@ export { create } from './Client.js' export { isError } from './Error.js' -export * as Select from './Select.js' +export { Select } from './Select.js' diff --git a/tests/_/schemaQueryOnly/generated/Select.ts b/tests/_/schemaQueryOnly/generated/Select.ts index b4f48eb7e..e1218d233 100644 --- a/tests/_/schemaQueryOnly/generated/Select.ts +++ b/tests/_/schemaQueryOnly/generated/Select.ts @@ -7,26 +7,31 @@ import { Index } from './Index.js' import { createSelect } from '../../../../src/entrypoints/alpha/client.js' export const Select = createSelect('default') -// Root Types -// ---------- +// Buildtime +// --------- -export type Query<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< - $SelectionSet, - Index, - 'Query' -> +export namespace Select { + // Root Types + // ---------- -// Object Types -// ------------ + export type Query<$SelectionSet extends SelectionSet.Root> = ResultSet.Root< + $SelectionSet, + Index, + 'Query' + > -// -- None -- + // Object Types + // ------------ -// Union Types -// ----------- + // -- None -- -// -- None -- + // Union Types + // ----------- -// Interface Types -// --------------- + // -- None -- -// -- None -- + // Interface Types + // --------------- + + // -- None -- +} diff --git a/tests/_/schemaQueryOnly/generated/_.ts b/tests/_/schemaQueryOnly/generated/_.ts index f871bbefd..5e2498a39 100644 --- a/tests/_/schemaQueryOnly/generated/_.ts +++ b/tests/_/schemaQueryOnly/generated/_.ts @@ -1,3 +1,3 @@ export { create } from './Client.js' export { isError } from './Error.js' -export * as Select from './Select.js' +export { Select } from './Select.js'