-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: colocate custom scalars logic (#1177)
- Loading branch information
1 parent
d3ffdc2
commit c580407
Showing
44 changed files
with
542 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from '../layers/1_Schema/__.js' | ||
export { Select } from '../layers/2_Select/__.js' | ||
export { ResultSet } from '../layers/3_Result/__.js' | ||
export { InferResult } from '../layers/3_InferResult/__.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 20 additions & 18 deletions
38
src/layers/3_Result/infer/Field.ts → src/layers/3_InferResult/Field.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
import type { Simplify } from 'type-fest' | ||
import type { TSError } from '../../../lib/TSError.js' | ||
import type { Schema } from '../../1_Schema/__.js' | ||
import type { Select } from '../../2_Select/__.js' | ||
import type { SchemaIndex } from '../../4_generator/generators/SchemaIndex.js' | ||
import type { InferInterface, InferObject, InferUnion } from './root.js' | ||
import type { TSError } from '../../lib/TSError.js' | ||
import type { Schema } from '../1_Schema/__.js' | ||
import type { Select } from '../2_Select/__.js' | ||
import type { SchemaIndex } from '../4_generator/generators/SchemaIndex.js' | ||
import type { Interface } from './Interface.js' | ||
import type { Object } from './Object.js' | ||
import type { Union } from './Union.js' | ||
|
||
// dprint-ignore | ||
export type InferField<$SelectionSet, $Field extends Schema.SomeField, $Schema extends SchemaIndex> = | ||
export type Field<$SelectionSet, $Field extends Schema.SomeField, $Schema extends SchemaIndex> = | ||
Simplify< | ||
$SelectionSet extends Select.Directive.Include.FieldStates.Negative | Select.Directive.Skip.FieldStates.Positive ? | ||
null : | ||
( | ||
| FieldDirectiveInclude<$SelectionSet> | ||
| FieldDirectiveSkip<$SelectionSet> | ||
| InferFieldType<Omit<$SelectionSet, '$'>, $Field['type'], $Schema> | ||
| FieldType<Omit<$SelectionSet, '$'>, $Field['type'], $Schema> | ||
) | ||
> | ||
|
||
// dprint-ignore | ||
type InferFieldType< | ||
type FieldType< | ||
$SelectionSet, | ||
$Type extends Schema.Output.Any, | ||
$Schema extends SchemaIndex | ||
> = | ||
$Type extends Schema.__typename<infer $Value> ? $Value : | ||
$Type extends Schema.Output.Nullable<infer $InnerType> ? null | InferFieldType<$SelectionSet, $InnerType, $Schema> : | ||
$Type extends Schema.Output.List<infer $InnerType> ? Array<InferFieldType<$SelectionSet, $InnerType, $Schema>> : | ||
$Type extends Schema.Output.Nullable<infer $InnerType> ? null | FieldType<$SelectionSet, $InnerType, $Schema> : | ||
$Type extends Schema.Output.List<infer $InnerType> ? Array<FieldType<$SelectionSet, $InnerType, $Schema>> : | ||
$Type extends Schema.Enum<infer _, infer $Members> ? $Members[number] : | ||
$Type extends Schema.Scalar.$Any ? ReturnType<$Type['codec']['decode']> : | ||
$Type extends Schema.Object$2 ? InferObject<$SelectionSet, $Schema, $Type> : | ||
$Type extends Schema.Interface ? InferInterface<$SelectionSet, $Schema, $Type> : | ||
$Type extends Schema.Union ? InferUnion<$SelectionSet, $Schema, $Type> : | ||
TSError<'InferFieldType', `Unknown type`, { $Type: $Type; $SelectionSet: $SelectionSet; $Schema:$Schema }> | ||
$Type extends Schema.Object$2 ? Object<$SelectionSet, $Schema, $Type> : | ||
$Type extends Schema.Interface ? Interface<$SelectionSet, $Schema, $Type> : | ||
$Type extends Schema.Union ? Union<$SelectionSet, $Schema, $Type> : | ||
TSError<'FieldType', `Unknown type`, { $Type: $Type; $SelectionSet: $SelectionSet; $Schema:$Schema }> | ||
|
||
// dprint-ignore | ||
type FieldDirectiveInclude<$SelectionSet> = | ||
$SelectionSet extends Select.Directive.Include.Field ? $SelectionSet extends Select.Directive.Include.FieldStates.Positive ? never | ||
: null | ||
: never | ||
: null | ||
: never | ||
|
||
// dprint-ignore | ||
type FieldDirectiveSkip<$SelectionSet> = | ||
$SelectionSet extends Select.Directive.Skip.Field ? $SelectionSet extends Select.Directive.Skip.FieldStates.Negative ? never | ||
: null | ||
: never | ||
: null | ||
: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { type GetKeyOr } from '../../lib/prelude.js' | ||
import type { Schema } from '../1_Schema/__.js' | ||
import type { Select } from '../2_Select/__.js' | ||
import type { SchemaIndex } from '../4_generator/generators/SchemaIndex.js' | ||
import type { Object } from './Object.js' | ||
|
||
// dprint-ignore | ||
export type InlineFragmentTypeConditional<$SelectionSet, $Node extends Schema.Output.Object$2, $Index extends SchemaIndex> = | ||
$Node extends any // force distribution | ||
? Object< | ||
& GetKeyOr< | ||
$SelectionSet, | ||
`${Select.InlineFragment.TypeConditionalKeyPrefix}${$Node['fields']['__typename']['type']['type']}`, | ||
{} | ||
> | ||
& Select.InlineFragment.OmitInlineFragmentsWithTypeConditions<$SelectionSet>, | ||
$Index, | ||
$Node | ||
> | ||
: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Schema } from '../1_Schema/__.js' | ||
import type { SchemaIndex } from '../4_generator/generators/SchemaIndex.js' | ||
import type { InlineFragmentTypeConditional } from './InlineFragment.js' | ||
|
||
// dprint-ignore | ||
export type Interface<$SelectionSet, $Index extends SchemaIndex, $Node extends Schema.Output.Interface> = | ||
InlineFragmentTypeConditional<$SelectionSet, $Node['implementors'][number], $Index> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { Simplify } from 'type-fest' | ||
import { type StringKeyof } from '../../lib/prelude.js' | ||
import type { TSError } from '../../lib/TSError.js' | ||
import type { Schema } from '../1_Schema/__.js' | ||
import type { Select } from '../2_Select/__.js' | ||
import type { SchemaIndex } from '../4_generator/generators/SchemaIndex.js' | ||
import type { Alias } from './Alias.js' | ||
import type { Field } from './Field.js' | ||
import type { ScalarsWildcard } from './ScalarsWildcard.js' | ||
|
||
// dprint-ignore | ||
export type Object<$SelectionSet, $Schema extends SchemaIndex, $Node extends Schema.Output.Object$2> = | ||
Select.SelectScalarsWildcard.IsSelectScalarsWildcard<$SelectionSet> extends true | ||
// todo what about when scalars wildcard is combined with other fields like relations? | ||
? ScalarsWildcard<$SelectionSet, $Schema,$Node> | ||
: | ||
Simplify<( | ||
& SelectionNonSelectAlias<$SelectionSet, $Schema, $Node> | ||
& Alias<$SelectionSet, $Schema, $Node> | ||
)> | ||
|
||
// dprint-ignore | ||
type SelectionNonSelectAlias<$SelectionSet , $Schema extends SchemaIndex, $Node extends Schema.Output.Object$2> = | ||
{ | ||
[$Select in PickSelectsPositiveIndicatorAndNotSelectAlias<$SelectionSet>]: | ||
$Select extends keyof $Node['fields'] | ||
? Field<$SelectionSet[$Select], $Node['fields'][$Select], $Schema> | ||
: Errors.UnknownFieldName<$Select, $Node> | ||
} | ||
|
||
// dprint-ignore | ||
export namespace Errors { | ||
export type UnknownFieldName<$FieldName extends string, $Object extends Schema.Object$2 | Schema.Output.RootType> = | ||
TSError<'Object', `field "${$FieldName}" does not exist on object "${$Object['fields']['__typename']['type']['type']}"`> | ||
} | ||
|
||
// dprint-ignore | ||
export type PickSelectsPositiveIndicatorAndNotSelectAlias<$SelectionSet> = StringKeyof<{ | ||
[ | ||
$FieldName in keyof $SelectionSet as $SelectionSet[$FieldName] extends Select.Indicator.Negative | ||
? never | ||
: $SelectionSet[$FieldName] extends any[] | ||
? never | ||
: $FieldName | ||
]: 0 | ||
}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Schema } from '../1_Schema/__.js' | ||
import type { SchemaIndex } from '../4_generator/generators/SchemaIndex.js' | ||
import type { Field } from './Field.js' | ||
|
||
export type ScalarsWildcard< | ||
$SelectionSet, | ||
$Index extends SchemaIndex, | ||
$Node extends Schema.Output.Object$2, | ||
> = { | ||
[$Key in keyof PickScalarFields<$Node>]: Field<$SelectionSet, $Node['fields'][$Key], $Index> | ||
} | ||
|
||
// dprint-ignore | ||
type PickScalarFields<$Object extends Schema.Output.Object$2> = { | ||
[ | ||
$Key in keyof $Object['fields'] | ||
as Schema.Output.UnwrapToNamed<$Object['fields'][$Key]['type']> extends Schema.Hybrid.Scalar.$Any | Schema.Output.__typename | ||
? $Key | ||
: never | ||
]: $Object['fields'][$Key] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Schema } from '../1_Schema/__.js' | ||
import type { SchemaIndex } from '../4_generator/generators/SchemaIndex.js' | ||
import type { InlineFragmentTypeConditional } from './InlineFragment.js' | ||
|
||
// dprint-ignore | ||
export type Union<$SelectionSet, $Index extends SchemaIndex, $Node extends Schema.Output.Union> = | ||
InlineFragmentTypeConditional<$SelectionSet, $Node['members'][number], $Index> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export * from './Alias.js' | ||
export * from './Field.js' | ||
export * from './Interface.js' | ||
export * from './Object.js' | ||
export * from './root.js' | ||
export * from './ScalarsWildcard.js' | ||
export * from './Union.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as InferResult from './_.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { type ExcludeNull } from '../../lib/prelude.js' | ||
import type { Schema } from '../1_Schema/__.js' | ||
import type { SchemaIndex } from '../4_generator/generators/SchemaIndex.js' | ||
import type { Object } from './Object.js' | ||
|
||
export type RootViaObject< | ||
$SelectionSet, | ||
$Schema extends SchemaIndex, | ||
$RootType extends Schema.Output.RootType, | ||
> = Root< | ||
$SelectionSet, | ||
$Schema, | ||
$RootType['fields']['__typename']['type']['type'] | ||
> | ||
|
||
// dprint-ignore | ||
export type Query<$SelectionSet, $Schema extends SchemaIndex> = | ||
Root<$SelectionSet, $Schema, 'Query'> | ||
|
||
// dprint-ignore | ||
export type Mutation<$SelectionSet, $Schema extends SchemaIndex> = | ||
Root<$SelectionSet, $Schema, 'Mutation'> | ||
|
||
// dprint-ignore | ||
export type Subscription<$SelectionSet, $Schema extends SchemaIndex> = | ||
Root<$SelectionSet, $Schema, 'Subscription'> | ||
|
||
export type Root< | ||
$SelectionSet, | ||
$Schema extends SchemaIndex, | ||
$RootTypeName extends Schema.RootTypeName, | ||
> = Object<$SelectionSet, $Schema, ExcludeNull<$Schema['Root'][$RootTypeName]>> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.