-
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.
improve(document-builder): simplification of all output cases! (#1269)
- Loading branch information
1 parent
7fd4449
commit 8f78882
Showing
20 changed files
with
1,106 additions
and
1,501 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
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 { assertEqual } from '../lib/assert-equal.js' | ||
import type { SimplifyDeep, SimplifyDeepExcept } from './Simplify.js' | ||
|
||
// dprint-ignore | ||
{ | ||
|
||
assertEqual<SimplifyDeep<{x:1|null}> , {x:1|null}>() | ||
assertEqual<SimplifyDeep<null | {x:1}> , null | {x:1}>() | ||
assertEqual<SimplifyDeep<null | {x?:1}> , null | {x?:1}>() | ||
assertEqual<SimplifyDeep<null | {x?:1|null}> , null | {x?:1|null}>() | ||
|
||
assertEqual<SimplifyDeepExcept<Date, null | Date> , null | Date>() | ||
assertEqual<SimplifyDeepExcept<Date, {}> , {}>() | ||
assertEqual<SimplifyDeepExcept<Date, { a: Date }> , { a: Date }>() | ||
assertEqual<SimplifyDeepExcept<Date, { a: 1 }> , { a: 1 }>() | ||
assertEqual<SimplifyDeepExcept<Date, { a: { b: Date } }> , { a: { b: Date } }>() | ||
assertEqual<SimplifyDeepExcept<Date, { a: { b: Date } }> , { a: { b: Date } }>() | ||
assertEqual<SimplifyDeepExcept<Date, { a: null | { b: Date } }> , { a: null | { b: Date } }>() | ||
|
||
} |
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,18 @@ | ||
import type { IntrospectionQuery } from 'graphql' | ||
import type { AnyAndUnknownToNever } from '../lib/prelude.js' | ||
|
||
export type SimplifyDeep<T> = SimplifyDeepExcept<never, T> | ||
|
||
// dprint-ignore | ||
export type SimplifyDeepExcept<$ExcludeType, $Type> = | ||
$Type extends any ? // distribute execution over $Type members | ||
|
||
// todo allow extensions to augment this list, with arbitrary types, not just custom scalars. | ||
$Type extends AnyAndUnknownToNever<$ExcludeType> | IntrospectionQuery | ||
? $Type | ||
: { | ||
[$Key in keyof $Type]: | ||
& SimplifyDeepExcept<$ExcludeType, $Type[$Key]> | ||
& ({} | 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 @@ | ||
export * from './Simplify.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 @@ | ||
export * as DocumentBuilder 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
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
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
Oops, something went wrong.