Skip to content

Commit

Permalink
fix(ts-client): select (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Apr 29, 2024
1 parent fb715d9 commit e2d1888
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 193 deletions.
152 changes: 76 additions & 76 deletions src/layers/2_generator/__snapshots__/files.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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'
"
`;

Expand Down Expand Up @@ -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<Index, 'Mutation'>> = ResultSet.Root<
$SelectionSet,
Index,
'Mutation'
>
export namespace Select {
// Root Types
// ----------
export type Query<$SelectionSet extends SelectionSet.Root<Index, 'Query'>> = ResultSet.Root<
$SelectionSet,
Index,
'Query'
>
export type Mutation<$SelectionSet extends SelectionSet.Root<Index, 'Mutation'>> = ResultSet.Root<
$SelectionSet,
Index,
'Mutation'
>
// Object Types
// ------------
export type Query<$SelectionSet extends SelectionSet.Root<Index, 'Query'>> = ResultSet.Root<
$SelectionSet,
Index,
'Query'
>
export type Bar<$SelectionSet extends SelectionSet.Object<Index['objects']['Bar'], Index>> = ResultSet.Object$<
$SelectionSet,
Index['objects']['Bar'],
Index
>
// Object Types
// ------------
export type DateObject1<$SelectionSet extends SelectionSet.Object<Index['objects']['DateObject1'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index>
export type Bar<$SelectionSet extends SelectionSet.Object<Index['objects']['Bar'], Index>> = ResultSet.Object$<
$SelectionSet,
Index['objects']['Bar'],
Index
>
export type DateObject2<$SelectionSet extends SelectionSet.Object<Index['objects']['DateObject2'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index>
export type DateObject1<$SelectionSet extends SelectionSet.Object<Index['objects']['DateObject1'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['DateObject1'], Index>
export type ErrorOne<$SelectionSet extends SelectionSet.Object<Index['objects']['ErrorOne'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['ErrorOne'], Index>
export type DateObject2<$SelectionSet extends SelectionSet.Object<Index['objects']['DateObject2'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['DateObject2'], Index>
export type ErrorTwo<$SelectionSet extends SelectionSet.Object<Index['objects']['ErrorTwo'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['ErrorTwo'], Index>
export type ErrorOne<$SelectionSet extends SelectionSet.Object<Index['objects']['ErrorOne'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['ErrorOne'], Index>
export type Foo<$SelectionSet extends SelectionSet.Object<Index['objects']['Foo'], Index>> = ResultSet.Object$<
$SelectionSet,
Index['objects']['Foo'],
Index
>
export type ErrorTwo<$SelectionSet extends SelectionSet.Object<Index['objects']['ErrorTwo'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['ErrorTwo'], Index>
export type Object1<$SelectionSet extends SelectionSet.Object<Index['objects']['Object1'], Index>> = ResultSet.Object$<
$SelectionSet,
Index['objects']['Object1'],
Index
>
export type Foo<$SelectionSet extends SelectionSet.Object<Index['objects']['Foo'], Index>> = ResultSet.Object$<
$SelectionSet,
Index['objects']['Foo'],
Index
>
export type Object1ImplementingInterface<
$SelectionSet extends SelectionSet.Object<Index['objects']['Object1ImplementingInterface'], Index>,
> = ResultSet.Object$<$SelectionSet, Index['objects']['Object1ImplementingInterface'], Index>
export type Object1<$SelectionSet extends SelectionSet.Object<Index['objects']['Object1'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['Object1'], Index>
export type Object2ImplementingInterface<
$SelectionSet extends SelectionSet.Object<Index['objects']['Object2ImplementingInterface'], Index>,
> = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index>
export type Object1ImplementingInterface<
$SelectionSet extends SelectionSet.Object<Index['objects']['Object1ImplementingInterface'], Index>,
> = ResultSet.Object$<$SelectionSet, Index['objects']['Object1ImplementingInterface'], Index>
export type ObjectNested<$SelectionSet extends SelectionSet.Object<Index['objects']['ObjectNested'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index>
export type Object2ImplementingInterface<
$SelectionSet extends SelectionSet.Object<Index['objects']['Object2ImplementingInterface'], Index>,
> = ResultSet.Object$<$SelectionSet, Index['objects']['Object2ImplementingInterface'], Index>
export type ObjectUnion<$SelectionSet extends SelectionSet.Object<Index['objects']['ObjectUnion'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index>
export type ObjectNested<$SelectionSet extends SelectionSet.Object<Index['objects']['ObjectNested'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['ObjectNested'], Index>
export type lowerCaseObject<$SelectionSet extends SelectionSet.Object<Index['objects']['lowerCaseObject'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index>
export type ObjectUnion<$SelectionSet extends SelectionSet.Object<Index['objects']['ObjectUnion'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['ObjectUnion'], Index>
export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object<Index['objects']['lowerCaseObject2'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index>
export type lowerCaseObject<$SelectionSet extends SelectionSet.Object<Index['objects']['lowerCaseObject'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject'], Index>
// Union Types
// -----------
export type lowerCaseObject2<$SelectionSet extends SelectionSet.Object<Index['objects']['lowerCaseObject2'], Index>> =
ResultSet.Object$<$SelectionSet, Index['objects']['lowerCaseObject2'], Index>
export type DateUnion<$SelectionSet extends SelectionSet.Union<Index['unions']['DateUnion'], Index>> = ResultSet.Union<
$SelectionSet,
Index['unions']['DateUnion'],
Index
>
// Union Types
// -----------
export type FooBarUnion<$SelectionSet extends SelectionSet.Union<Index['unions']['FooBarUnion'], Index>> =
ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index>
export type DateUnion<$SelectionSet extends SelectionSet.Union<Index['unions']['DateUnion'], Index>> =
ResultSet.Union<$SelectionSet, Index['unions']['DateUnion'], Index>
export type Result<$SelectionSet extends SelectionSet.Union<Index['unions']['Result'], Index>> = ResultSet.Union<
$SelectionSet,
Index['unions']['Result'],
Index
>
export type FooBarUnion<$SelectionSet extends SelectionSet.Union<Index['unions']['FooBarUnion'], Index>> =
ResultSet.Union<$SelectionSet, Index['unions']['FooBarUnion'], Index>
export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union<Index['unions']['lowerCaseUnion'], Index>> =
ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index>
export type Result<$SelectionSet extends SelectionSet.Union<Index['unions']['Result'], Index>> = ResultSet.Union<
$SelectionSet,
Index['unions']['Result'],
Index
>
// Interface Types
// ---------------
export type lowerCaseUnion<$SelectionSet extends SelectionSet.Union<Index['unions']['lowerCaseUnion'], Index>> =
ResultSet.Union<$SelectionSet, Index['unions']['lowerCaseUnion'], Index>
export type DateInterface1<$SelectionSet extends SelectionSet.Interface<Index['interfaces']['DateInterface1'], Index>> =
ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index>
// Interface Types
// ---------------
export type Error<$SelectionSet extends SelectionSet.Interface<Index['interfaces']['Error'], Index>> =
ResultSet.Interface<$SelectionSet, Index['interfaces']['Error'], Index>
export type DateInterface1<
$SelectionSet extends SelectionSet.Interface<Index['interfaces']['DateInterface1'], Index>,
> = ResultSet.Interface<$SelectionSet, Index['interfaces']['DateInterface1'], Index>
export type Interface<$SelectionSet extends SelectionSet.Interface<Index['interfaces']['Interface'], Index>> =
ResultSet.Interface<$SelectionSet, Index['interfaces']['Interface'], Index>
export type Error<$SelectionSet extends SelectionSet.Interface<Index['interfaces']['Error'], Index>> =
ResultSet.Interface<$SelectionSet, Index['interfaces']['Error'], Index>
export type Interface<$SelectionSet extends SelectionSet.Interface<Index['interfaces']['Interface'], Index>> =
ResultSet.Interface<$SelectionSet, Index['interfaces']['Interface'], Index>
}
"
`;
Expand Down
18 changes: 12 additions & 6 deletions src/layers/2_generator/code/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Index, '${type.name}'>> = ResultSet.Root<$SelectionSet, Index, '${type.name}'>\n`
Expand All @@ -41,6 +45,8 @@ export const { generate: generateSelect, moduleName: moduleNameSelect } = create
return `export type ${type.name}<$SelectionSet extends SelectionSet.Interface<Index['interfaces']['${type.name}'], Index>> = ResultSet.Interface<$SelectionSet, Index['interfaces']['${type.name}'], Index>\n`
}))

code.push(`}`) // namespace Select

return code.join(`\n`)
},
)
2 changes: 1 addition & 1 deletion src/layers/2_generator/code/_.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'`,
)
Expand Down

0 comments on commit e2d1888

Please sign in to comment.