diff --git a/.changeset/fuzzy-poets-doubt.md b/.changeset/fuzzy-poets-doubt.md new file mode 100644 index 00000000000..8a8e0a30bc7 --- /dev/null +++ b/.changeset/fuzzy-poets-doubt.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/typescript-operations': patch +--- + +Re-implement inputMaybeValue diff --git a/dev-test/githunt/typed-document-nodes.ts b/dev-test/githunt/typed-document-nodes.ts index 275d45818d5..938f36470e3 100644 --- a/dev-test/githunt/typed-document-nodes.ts +++ b/dev-test/githunt/typed-document-nodes.ts @@ -16,8 +16,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit?: number | null; - offset?: number | null; + limit?: number | null | undefined; + offset?: number | null | undefined; }>; export type CommentQuery = { @@ -73,8 +73,8 @@ export type FeedEntryFragment = { export type FeedQueryVariables = Exact<{ type: FeedType; - offset?: number | null; - limit?: number | null; + offset?: number | null | undefined; + limit?: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/githunt/types.avoidOptionals.ts b/dev-test/githunt/types.avoidOptionals.ts index 69796beb7e6..5ebe78c0a9c 100644 --- a/dev-test/githunt/types.avoidOptionals.ts +++ b/dev-test/githunt/types.avoidOptionals.ts @@ -15,8 +15,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit: number | null; - offset: number | null; + limit: number | null | undefined; + offset: number | null | undefined; }>; export type CommentQuery = { @@ -72,8 +72,8 @@ export type FeedEntryFragment = { export type FeedQueryVariables = Exact<{ type: FeedType; - offset: number | null; - limit: number | null; + offset: number | null | undefined; + limit: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/githunt/types.d.ts b/dev-test/githunt/types.d.ts index 87793fe2a3f..37dd3b4e1bd 100644 --- a/dev-test/githunt/types.d.ts +++ b/dev-test/githunt/types.d.ts @@ -15,8 +15,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit?: number | null; - offset?: number | null; + limit?: number | null | undefined; + offset?: number | null | undefined; }>; export type CommentQuery = { @@ -72,8 +72,8 @@ export type FeedEntryFragment = { export type FeedQueryVariables = Exact<{ type: FeedType; - offset?: number | null; - limit?: number | null; + offset?: number | null | undefined; + limit?: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/githunt/types.enumsAsTypes.ts b/dev-test/githunt/types.enumsAsTypes.ts index 87793fe2a3f..37dd3b4e1bd 100644 --- a/dev-test/githunt/types.enumsAsTypes.ts +++ b/dev-test/githunt/types.enumsAsTypes.ts @@ -15,8 +15,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit?: number | null; - offset?: number | null; + limit?: number | null | undefined; + offset?: number | null | undefined; }>; export type CommentQuery = { @@ -72,8 +72,8 @@ export type FeedEntryFragment = { export type FeedQueryVariables = Exact<{ type: FeedType; - offset?: number | null; - limit?: number | null; + offset?: number | null | undefined; + limit?: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/githunt/types.flatten.preResolveTypes.ts b/dev-test/githunt/types.flatten.preResolveTypes.ts index 5315ce1bae5..eebb41b2ad7 100644 --- a/dev-test/githunt/types.flatten.preResolveTypes.ts +++ b/dev-test/githunt/types.flatten.preResolveTypes.ts @@ -15,8 +15,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit?: number | null; - offset?: number | null; + limit?: number | null | undefined; + offset?: number | null | undefined; }>; export type CommentQuery = { @@ -48,8 +48,8 @@ export type CurrentUserForProfileQuery = { currentUser: { login: string; avatar_ export type FeedQueryVariables = Exact<{ type: FeedType; - offset?: number | null; - limit?: number | null; + offset?: number | null | undefined; + limit?: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/githunt/types.immutableTypes.ts b/dev-test/githunt/types.immutableTypes.ts index 2ed4050f66c..f61d436f01f 100644 --- a/dev-test/githunt/types.immutableTypes.ts +++ b/dev-test/githunt/types.immutableTypes.ts @@ -15,8 +15,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit?: number | null; - offset?: number | null; + limit?: number | null | undefined; + offset?: number | null | undefined; }>; export type CommentQuery = { @@ -74,8 +74,8 @@ export type FeedEntryFragment = { export type FeedQueryVariables = Exact<{ type: FeedType; - offset?: number | null; - limit?: number | null; + offset?: number | null | undefined; + limit?: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts b/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts index 87793fe2a3f..37dd3b4e1bd 100644 --- a/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts +++ b/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts @@ -15,8 +15,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit?: number | null; - offset?: number | null; + limit?: number | null | undefined; + offset?: number | null | undefined; }>; export type CommentQuery = { @@ -72,8 +72,8 @@ export type FeedEntryFragment = { export type FeedQueryVariables = Exact<{ type: FeedType; - offset?: number | null; - limit?: number | null; + offset?: number | null | undefined; + limit?: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/githunt/types.preResolveTypes.ts b/dev-test/githunt/types.preResolveTypes.ts index 87793fe2a3f..37dd3b4e1bd 100644 --- a/dev-test/githunt/types.preResolveTypes.ts +++ b/dev-test/githunt/types.preResolveTypes.ts @@ -15,8 +15,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit?: number | null; - offset?: number | null; + limit?: number | null | undefined; + offset?: number | null | undefined; }>; export type CommentQuery = { @@ -72,8 +72,8 @@ export type FeedEntryFragment = { export type FeedQueryVariables = Exact<{ type: FeedType; - offset?: number | null; - limit?: number | null; + offset?: number | null | undefined; + limit?: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/githunt/types.ts b/dev-test/githunt/types.ts index 87793fe2a3f..37dd3b4e1bd 100644 --- a/dev-test/githunt/types.ts +++ b/dev-test/githunt/types.ts @@ -15,8 +15,8 @@ export type OnCommentAddedSubscription = { export type CommentQueryVariables = Exact<{ repoFullName: string; - limit?: number | null; - offset?: number | null; + limit?: number | null | undefined; + offset?: number | null | undefined; }>; export type CommentQuery = { @@ -72,8 +72,8 @@ export type FeedEntryFragment = { export type FeedQueryVariables = Exact<{ type: FeedType; - offset?: number | null; - limit?: number | null; + offset?: number | null | undefined; + limit?: number | null | undefined; }>; export type FeedQuery = { diff --git a/dev-test/standalone-operations/import-schema-types/_types.generated.ts b/dev-test/standalone-operations/import-schema-types/_types.generated.ts index 775c69049eb..506b64e32b0 100644 --- a/dev-test/standalone-operations/import-schema-types/_types.generated.ts +++ b/dev-test/standalone-operations/import-schema-types/_types.generated.ts @@ -3,7 +3,7 @@ import type * as Types from './_base.generated.js'; type Exact = { [K in keyof T]: T[K] }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type WithVariablesQueryVariables = Exact<{ - role?: Types.UserRole | null; + role?: Types.UserRole | null | undefined; }>; export type WithVariablesQuery = { user: { id: string; name: string } | null }; diff --git a/dev-test/star-wars/types.avoidOptionals.ts b/dev-test/star-wars/types.avoidOptionals.ts index 5108083b866..30ca5fe2966 100644 --- a/dev-test/star-wars/types.avoidOptionals.ts +++ b/dev-test/star-wars/types.avoidOptionals.ts @@ -17,19 +17,19 @@ export type CreateReviewForEpisodeMutationVariables = Exact<{ export type CreateReviewForEpisodeMutation = { createReview: { stars: number; commentary: string | null } | null }; export type ExcludeQueryAlphaQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; }>; export type ExcludeQueryAlphaQuery = { hero: { name: string } | { name: string } | null }; export type ExcludeQueryBetaQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; }>; export type ExcludeQueryBetaQuery = { hero: { name: string } | { name: string } | null }; export type HeroAndFriendsNamesQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; }>; export type HeroAndFriendsNamesQuery = { @@ -46,7 +46,7 @@ export type HeroAppearsInQuery = { }; export type HeroDetailsQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; }>; export type HeroDetailsQuery = { @@ -60,7 +60,7 @@ type HeroDetails_Human_Fragment = { height: number | null; name: string }; export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; export type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; }>; export type HeroDetailsWithFragmentQuery = { @@ -68,27 +68,27 @@ export type HeroDetailsWithFragmentQuery = { }; export type HeroNameQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; }>; export type HeroNameQuery = { hero: { name: string } | { name: string } | null }; export type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; includeName: boolean; }>; export type HeroNameConditionalInclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; skipName: boolean; }>; export type HeroNameConditionalExclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; }>; export type HeroParentTypeDependentFieldQuery = { @@ -99,7 +99,7 @@ export type HeroParentTypeDependentFieldQuery = { }; export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode: Episode | null; + episode: Episode | null | undefined; }>; export type HeroTypeDependentAliasedFieldQuery = { diff --git a/dev-test/star-wars/types.excludeQueryAlpha.ts b/dev-test/star-wars/types.excludeQueryAlpha.ts index a7cf9605766..13c53f75559 100644 --- a/dev-test/star-wars/types.excludeQueryAlpha.ts +++ b/dev-test/star-wars/types.excludeQueryAlpha.ts @@ -17,13 +17,13 @@ export type CreateReviewForEpisodeMutationVariables = Exact<{ export type CreateReviewForEpisodeMutation = { createReview: { stars: number; commentary: string | null } | null }; export type ExcludeQueryBetaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryBetaQuery = { hero: { name: string } | { name: string } | null }; export type HeroAndFriendsNamesQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroAndFriendsNamesQuery = { @@ -40,7 +40,7 @@ export type HeroAppearsInQuery = { }; export type HeroDetailsQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsQuery = { @@ -54,7 +54,7 @@ type HeroDetails_Human_Fragment = { height: number | null; name: string }; export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; export type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsWithFragmentQuery = { @@ -62,27 +62,27 @@ export type HeroDetailsWithFragmentQuery = { }; export type HeroNameQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroNameQuery = { hero: { name: string } | { name: string } | null }; export type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; includeName: boolean; }>; export type HeroNameConditionalInclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; skipName: boolean; }>; export type HeroNameConditionalExclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroParentTypeDependentFieldQuery = { @@ -93,7 +93,7 @@ export type HeroParentTypeDependentFieldQuery = { }; export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroTypeDependentAliasedFieldQuery = { diff --git a/dev-test/star-wars/types.excludeQueryBeta.ts b/dev-test/star-wars/types.excludeQueryBeta.ts index f0984cce895..5760e666070 100644 --- a/dev-test/star-wars/types.excludeQueryBeta.ts +++ b/dev-test/star-wars/types.excludeQueryBeta.ts @@ -17,13 +17,13 @@ export type CreateReviewForEpisodeMutationVariables = Exact<{ export type CreateReviewForEpisodeMutation = { createReview: { stars: number; commentary: string | null } | null }; export type ExcludeQueryAlphaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryAlphaQuery = { hero: { name: string } | { name: string } | null }; export type HeroAndFriendsNamesQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroAndFriendsNamesQuery = { @@ -40,7 +40,7 @@ export type HeroAppearsInQuery = { }; export type HeroDetailsQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsQuery = { @@ -54,7 +54,7 @@ type HeroDetails_Human_Fragment = { height: number | null; name: string }; export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; export type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsWithFragmentQuery = { @@ -62,27 +62,27 @@ export type HeroDetailsWithFragmentQuery = { }; export type HeroNameQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroNameQuery = { hero: { name: string } | { name: string } | null }; export type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; includeName: boolean; }>; export type HeroNameConditionalInclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; skipName: boolean; }>; export type HeroNameConditionalExclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroParentTypeDependentFieldQuery = { @@ -93,7 +93,7 @@ export type HeroParentTypeDependentFieldQuery = { }; export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroTypeDependentAliasedFieldQuery = { diff --git a/dev-test/star-wars/types.globallyAvailable.d.ts b/dev-test/star-wars/types.globallyAvailable.d.ts index bd818339896..7b3d5f049a9 100644 --- a/dev-test/star-wars/types.globallyAvailable.d.ts +++ b/dev-test/star-wars/types.globallyAvailable.d.ts @@ -17,19 +17,19 @@ type CreateReviewForEpisodeMutationVariables = Exact<{ type CreateReviewForEpisodeMutation = { createReview: { stars: number; commentary: string | null } | null }; type ExcludeQueryAlphaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; type ExcludeQueryAlphaQuery = { hero: { name: string } | { name: string } | null }; type ExcludeQueryBetaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; type ExcludeQueryBetaQuery = { hero: { name: string } | { name: string } | null }; type HeroAndFriendsNamesQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; type HeroAndFriendsNamesQuery = { @@ -46,7 +46,7 @@ type HeroAppearsInQuery = { }; type HeroDetailsQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; type HeroDetailsQuery = { @@ -60,7 +60,7 @@ type HeroDetails_Human_Fragment = { height: number | null; name: string }; type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; type HeroDetailsWithFragmentQuery = { @@ -68,27 +68,27 @@ type HeroDetailsWithFragmentQuery = { }; type HeroNameQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; type HeroNameQuery = { hero: { name: string } | { name: string } | null }; type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; includeName: boolean; }>; type HeroNameConditionalInclusionQuery = { hero: { name?: string } | { name?: string } | null }; type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; skipName: boolean; }>; type HeroNameConditionalExclusionQuery = { hero: { name?: string } | { name?: string } | null }; type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; type HeroParentTypeDependentFieldQuery = { @@ -99,7 +99,7 @@ type HeroParentTypeDependentFieldQuery = { }; type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; type HeroTypeDependentAliasedFieldQuery = { hero: { property: string | null } | { property: string | null } | null }; diff --git a/dev-test/star-wars/types.immutableTypes.ts b/dev-test/star-wars/types.immutableTypes.ts index 06f6c5314e5..a2ab0c4c7f4 100644 --- a/dev-test/star-wars/types.immutableTypes.ts +++ b/dev-test/star-wars/types.immutableTypes.ts @@ -19,19 +19,19 @@ export type CreateReviewForEpisodeMutation = { }; export type ExcludeQueryAlphaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryAlphaQuery = { readonly hero: { readonly name: string } | { readonly name: string } | null }; export type ExcludeQueryBetaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryBetaQuery = { readonly hero: { readonly name: string } | { readonly name: string } | null }; export type HeroAndFriendsNamesQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroAndFriendsNamesQuery = { @@ -57,7 +57,7 @@ export type HeroAppearsInQuery = { }; export type HeroDetailsQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsQuery = { @@ -74,7 +74,7 @@ type HeroDetails_Human_Fragment = { readonly height: number | null; readonly nam export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; export type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsWithFragmentQuery = { @@ -85,13 +85,13 @@ export type HeroDetailsWithFragmentQuery = { }; export type HeroNameQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroNameQuery = { readonly hero: { readonly name: string } | { readonly name: string } | null }; export type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; includeName: boolean; }>; @@ -100,7 +100,7 @@ export type HeroNameConditionalInclusionQuery = { }; export type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; skipName: boolean; }>; @@ -109,7 +109,7 @@ export type HeroNameConditionalExclusionQuery = { }; export type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroParentTypeDependentFieldQuery = { @@ -130,7 +130,7 @@ export type HeroParentTypeDependentFieldQuery = { }; export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroTypeDependentAliasedFieldQuery = { diff --git a/dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts b/dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts index bbc6c6f53df..45d5f165a8b 100644 --- a/dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts +++ b/dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts @@ -17,19 +17,19 @@ export type CreateReviewForEpisodeMutationVariables = Exact<{ export type CreateReviewForEpisodeMutation = { createReview: { stars: number; commentary: string | null } | null }; export type ExcludeQueryAlphaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryAlphaQuery = { hero: { name: string } | { name: string } | null }; export type ExcludeQueryBetaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryBetaQuery = { hero: { name: string } | { name: string } | null }; export type HeroAndFriendsNamesQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroAndFriendsNamesQuery = { @@ -46,7 +46,7 @@ export type HeroAppearsInQuery = { }; export type HeroDetailsQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsQuery = { @@ -60,7 +60,7 @@ type HeroDetails_Human_Fragment = { height: number | null; name: string }; export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; export type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsWithFragmentQuery = { @@ -68,27 +68,27 @@ export type HeroDetailsWithFragmentQuery = { }; export type HeroNameQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroNameQuery = { hero: { name: string } | { name: string } | null }; export type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; includeName: boolean; }>; export type HeroNameConditionalInclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; skipName: boolean; }>; export type HeroNameConditionalExclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroParentTypeDependentFieldQuery = { @@ -99,7 +99,7 @@ export type HeroParentTypeDependentFieldQuery = { }; export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroTypeDependentAliasedFieldQuery = { diff --git a/dev-test/star-wars/types.preResolveTypes.ts b/dev-test/star-wars/types.preResolveTypes.ts index bbc6c6f53df..45d5f165a8b 100644 --- a/dev-test/star-wars/types.preResolveTypes.ts +++ b/dev-test/star-wars/types.preResolveTypes.ts @@ -17,19 +17,19 @@ export type CreateReviewForEpisodeMutationVariables = Exact<{ export type CreateReviewForEpisodeMutation = { createReview: { stars: number; commentary: string | null } | null }; export type ExcludeQueryAlphaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryAlphaQuery = { hero: { name: string } | { name: string } | null }; export type ExcludeQueryBetaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryBetaQuery = { hero: { name: string } | { name: string } | null }; export type HeroAndFriendsNamesQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroAndFriendsNamesQuery = { @@ -46,7 +46,7 @@ export type HeroAppearsInQuery = { }; export type HeroDetailsQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsQuery = { @@ -60,7 +60,7 @@ type HeroDetails_Human_Fragment = { height: number | null; name: string }; export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; export type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsWithFragmentQuery = { @@ -68,27 +68,27 @@ export type HeroDetailsWithFragmentQuery = { }; export type HeroNameQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroNameQuery = { hero: { name: string } | { name: string } | null }; export type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; includeName: boolean; }>; export type HeroNameConditionalInclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; skipName: boolean; }>; export type HeroNameConditionalExclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroParentTypeDependentFieldQuery = { @@ -99,7 +99,7 @@ export type HeroParentTypeDependentFieldQuery = { }; export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroTypeDependentAliasedFieldQuery = { diff --git a/dev-test/star-wars/types.skipSchema.ts b/dev-test/star-wars/types.skipSchema.ts index bbc6c6f53df..45d5f165a8b 100644 --- a/dev-test/star-wars/types.skipSchema.ts +++ b/dev-test/star-wars/types.skipSchema.ts @@ -17,19 +17,19 @@ export type CreateReviewForEpisodeMutationVariables = Exact<{ export type CreateReviewForEpisodeMutation = { createReview: { stars: number; commentary: string | null } | null }; export type ExcludeQueryAlphaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryAlphaQuery = { hero: { name: string } | { name: string } | null }; export type ExcludeQueryBetaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryBetaQuery = { hero: { name: string } | { name: string } | null }; export type HeroAndFriendsNamesQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroAndFriendsNamesQuery = { @@ -46,7 +46,7 @@ export type HeroAppearsInQuery = { }; export type HeroDetailsQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsQuery = { @@ -60,7 +60,7 @@ type HeroDetails_Human_Fragment = { height: number | null; name: string }; export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; export type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsWithFragmentQuery = { @@ -68,27 +68,27 @@ export type HeroDetailsWithFragmentQuery = { }; export type HeroNameQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroNameQuery = { hero: { name: string } | { name: string } | null }; export type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; includeName: boolean; }>; export type HeroNameConditionalInclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; skipName: boolean; }>; export type HeroNameConditionalExclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroParentTypeDependentFieldQuery = { @@ -99,7 +99,7 @@ export type HeroParentTypeDependentFieldQuery = { }; export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroTypeDependentAliasedFieldQuery = { diff --git a/dev-test/star-wars/types.ts b/dev-test/star-wars/types.ts index bbc6c6f53df..45d5f165a8b 100644 --- a/dev-test/star-wars/types.ts +++ b/dev-test/star-wars/types.ts @@ -17,19 +17,19 @@ export type CreateReviewForEpisodeMutationVariables = Exact<{ export type CreateReviewForEpisodeMutation = { createReview: { stars: number; commentary: string | null } | null }; export type ExcludeQueryAlphaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryAlphaQuery = { hero: { name: string } | { name: string } | null }; export type ExcludeQueryBetaQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type ExcludeQueryBetaQuery = { hero: { name: string } | { name: string } | null }; export type HeroAndFriendsNamesQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroAndFriendsNamesQuery = { @@ -46,7 +46,7 @@ export type HeroAppearsInQuery = { }; export type HeroDetailsQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsQuery = { @@ -60,7 +60,7 @@ type HeroDetails_Human_Fragment = { height: number | null; name: string }; export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; export type HeroDetailsWithFragmentQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroDetailsWithFragmentQuery = { @@ -68,27 +68,27 @@ export type HeroDetailsWithFragmentQuery = { }; export type HeroNameQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroNameQuery = { hero: { name: string } | { name: string } | null }; export type HeroNameConditionalInclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; includeName: boolean; }>; export type HeroNameConditionalInclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroNameConditionalExclusionQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; skipName: boolean; }>; export type HeroNameConditionalExclusionQuery = { hero: { name?: string } | { name?: string } | null }; export type HeroParentTypeDependentFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroParentTypeDependentFieldQuery = { @@ -99,7 +99,7 @@ export type HeroParentTypeDependentFieldQuery = { }; export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ - episode?: Episode | null; + episode?: Episode | null | undefined; }>; export type HeroTypeDependentAliasedFieldQuery = { diff --git a/packages/plugins/typescript/operations/src/config.ts b/packages/plugins/typescript/operations/src/config.ts index 9dcbcb6ce01..b7f3edb545b 100644 --- a/packages/plugins/typescript/operations/src/config.ts +++ b/packages/plugins/typescript/operations/src/config.ts @@ -230,11 +230,13 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { */ addOperationExport?: boolean; /** - * @description Allow to override the type value of `Maybe`. + * @description Allows overriding the type value of nullable fields to match GraphQL client's runtime behaviour. * @default T | null * * @exampleMarkdown * ## Allow undefined + * By default, a GraphQL server will return either the expected type or `null` for a nullable field. + * `maybeValue` option could be used to change this behaviour if your GraphQL client does something different such as returning `undefined`. * ```ts filename="codegen.ts" * import type { CodegenConfig } from '@graphql-codegen/cli'; * @@ -242,7 +244,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { * // ... * generates: { * 'path/to/file.ts': { - * plugins: ['typescript'], + * plugins: ['typescript-operations'], * config: { * maybeValue: 'T | null | undefined' * }, @@ -251,26 +253,38 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { * }; * export default config; * ``` + */ + maybeValue?: string; + + /** + * @description Allows overriding the type of Input and Variables nullable types. + * @default T | null | undefined + * + * @exampleMarkdown + * ## Disallow `undefined` + * Disallowing `undefined` is useful if you want to force explicit null to be passed in as Variables to the server. Use `inputMaybeValue: 'T | null'` with `avoidOptionals.inputValue: true` to achieve this. * - * ## Allow `null` in resolvers: * ```ts filename="codegen.ts" - * import type { CodegenConfig } from '@graphql-codegen/cli'; + * import type { CodegenConfig } from '@graphql-codegen/cli' * - * const config: CodegenConfig = { - * // ... - * generates: { - * 'path/to/file.ts': { - * plugins: ['typescript'], - * config: { - * maybeValue: 'T extends PromiseLike ? Promise : T | null' - * }, - * }, - * }, - * }; - * export default config; + * const config: CodegenConfig = { + * // ... + * generates: { + * 'path/to/file.ts': { + * plugins: ['typescript-operations'], + * config: { + * avoidOptionals: { + * inputValue: true, + * }, + * inputMaybeValue: 'T | null' + * } + * } + * } + * } + * export default config * ``` */ - maybeValue?: string; + inputMaybeValue?: string; /** * @description Adds undefined as a possible type for query variables diff --git a/packages/plugins/typescript/operations/src/ts-operation-variables-to-object.ts b/packages/plugins/typescript/operations/src/ts-operation-variables-to-object.ts index 0d5e4c1eb30..cee63b694f2 100644 --- a/packages/plugins/typescript/operations/src/ts-operation-variables-to-object.ts +++ b/packages/plugins/typescript/operations/src/ts-operation-variables-to-object.ts @@ -15,14 +15,16 @@ export const SCALARS = { Boolean: 'boolean', }; -const MAYBE_SUFFIX = ' | null'; - export class TypeScriptOperationVariablesToObject extends OperationVariablesToObject { constructor( + private _config: { + avoidOptionals: NormalizedAvoidOptionalsConfig; + immutableTypes: boolean; + inputMaybeValue: string; + inputMaybeValueSuffix: string; + }, _scalars: NormalizedScalarsMap, _convertName: ConvertNameFn, - private _avoidOptionals: NormalizedAvoidOptionalsConfig, - private _immutableTypes: boolean, _namespacedImportName: string | null, _enumNames: string[], _enumPrefix: boolean, @@ -52,18 +54,28 @@ export class TypeScriptOperationVariablesToObject extends OperationVariablesToOb } protected clearOptional(str: string): string { - if (str?.endsWith(MAYBE_SUFFIX)) { - return (str = str.substring(0, str.length - MAYBE_SUFFIX.length)); + const maybeSuffix = this._config.inputMaybeValueSuffix; + + if (str.endsWith(maybeSuffix)) { + return (str = str.substring(0, str.length - maybeSuffix.length)); } return str; } - protected getAvoidOption(isNonNullType: boolean, hasDefaultValue: boolean) { - const options = this._avoidOptionals; + protected getAvoidOption(isNonNullType: boolean, hasDefaultValue: boolean): boolean { + const options = this._config.avoidOptionals; return ((options.object || !options.defaultValue) && hasDefaultValue) || (!options.object && !isNonNullType); } + protected getScalar(name: string): string { + return this._scalars[name]?.input ?? SCALARS[name] ?? 'unknown'; + } + + protected getPunctuation(): string { + return ';'; + } + public wrapAstTypeWithModifiers(baseType: string, typeNode: TypeNode, applyCoercion = false): string { if (typeNode.kind === Kind.NON_NULL_TYPE) { const type = this.wrapAstTypeWithModifiers(baseType, typeNode.type, applyCoercion); @@ -75,21 +87,15 @@ export class TypeScriptOperationVariablesToObject extends OperationVariablesToOb const listInputCoercionExtension = applyCoercion ? ` | ${innerType}` : ''; return this.wrapMaybe( - `${this._immutableTypes ? 'ReadonlyArray' : 'Array'}<${innerType}>${listInputCoercionExtension}` + `${this._config.immutableTypes ? 'ReadonlyArray' : 'Array'}<${innerType}>${listInputCoercionExtension}` ); } return this.wrapMaybe(baseType); } protected wrapMaybe(type: string): string { - return type?.endsWith(MAYBE_SUFFIX) ? type : `${type}${MAYBE_SUFFIX}`; - } + const maybeSuffix = this._config.inputMaybeValueSuffix; - protected getScalar(name: string): string { - return this._scalars?.[name]?.input ?? SCALARS[name] ?? 'unknown'; - } - - protected getPunctuation(): string { - return ';'; + return type.endsWith(maybeSuffix) ? type : `${type}${maybeSuffix}`; } } diff --git a/packages/plugins/typescript/operations/src/visitor.ts b/packages/plugins/typescript/operations/src/visitor.ts index 9fa029ea661..64ef7954336 100644 --- a/packages/plugins/typescript/operations/src/visitor.ts +++ b/packages/plugins/typescript/operations/src/visitor.ts @@ -54,6 +54,7 @@ export interface TypeScriptDocumentsParsedConfig extends ParsedDocumentsConfig { immutableTypes: boolean; noExport: boolean; maybeValue: string; + inputMaybeValue: string; allowUndefinedQueryVariables: boolean; enumType: ConvertSchemaEnumToDeclarationBlockString['outputType']; enumValues: ParsedEnumValuesMap; @@ -75,6 +76,7 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor< protected _usedNamedInputTypes: UsedNamedInputTypes = {}; protected _needsExactUtilityType: boolean = false; private _outputPath: string; + private _inputMaybeValueSuffix: string; constructor( schema: GraphQLSchema, @@ -101,6 +103,7 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor< ignoreEnumValuesFromSchema: getConfigValue(config.ignoreEnumValuesFromSchema, false), futureProofEnums: getConfigValue(config.futureProofEnums, false), maybeValue: getConfigValue(config.maybeValue, 'T | null'), + inputMaybeValue: getConfigValue(config.inputMaybeValue, 'T | null | undefined'), } as TypeScriptDocumentsParsedConfig, schema ); @@ -154,16 +157,23 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor< this.config ) ); + + this._inputMaybeValueSuffix = this.config.inputMaybeValue.replace('T', ''); // e.g. turns `T | null | undefined` to ` | null | undefined` + const enumsNames = Object.keys(schema.getTypeMap()).filter(typeName => isEnumType(schema.getType(typeName))); this.setVariablesTransformer( new TypeScriptOperationVariablesToObject( + { + // FIXME: this is the legacy avoidOptionals which was used to make Result fields non-optional. This use case is no longer valid. + // It's also being used for Variables so people could already be using it. + // Maybe it's better to deprecate and remove, to see what users think. + avoidOptionals: this.config.avoidOptionals, + immutableTypes: this.config.immutableTypes, + inputMaybeValue: this.config.inputMaybeValue, + inputMaybeValueSuffix: this._inputMaybeValueSuffix, + }, this.scalars, this.convertName.bind(this), - // FIXME: this is the legacy avoidOptionals which was used to make Result fields non-optional. This use case is no longer valid. - // It's also being used for Variables so people could already be using it. - // Maybe it's better to deprecate and remove, to see what users think. - this.config.avoidOptionals, - this.config.immutableTypes, this.config.namespacedImportName, enumsNames, this.config.enumPrefix, @@ -267,7 +277,7 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor< typePart = usedInputType.tsType; // If the schema is correct, when reversing typeNodes, the first node would be `NamedType`, which means we can safely set it as the base for typePart if (!typeNode.isNonNullable) { - typePart += ' | null | undefined'; + typePart += this._inputMaybeValueSuffix; } continue; } @@ -275,7 +285,7 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor< if (typeNode.type === 'ListType') { typePart = `Array<${typePart}>`; if (!typeNode.isNonNullable) { - typePart += ' | null | undefined'; + typePart += this._inputMaybeValueSuffix; } } } diff --git a/packages/plugins/typescript/operations/tests/ts-documents.spec.ts b/packages/plugins/typescript/operations/tests/ts-documents.spec.ts index 6849898aae5..c596eaec2a6 100644 --- a/packages/plugins/typescript/operations/tests/ts-documents.spec.ts +++ b/packages/plugins/typescript/operations/tests/ts-documents.spec.ts @@ -2719,13 +2719,13 @@ export type Q2Query = { search: Array< }; export type TestQueryQueryVariables = Exact<{ - username?: string | null; - email?: string | null; + username?: string | null | undefined; + email?: string | null | undefined; password: string; - input?: InputType | null; + input?: InputType | null | undefined; mandatoryInput: InputType; - testArray?: Array | string | null; - requireString: Array | string; + testArray?: Array | string | null | undefined; + requireString: Array | string; innerRequired: Array | string; }>; @@ -2749,7 +2749,7 @@ export type Q2Query = { search: Array< expect(content).toMatchInlineSnapshot( ` "export type TestQueryQueryVariables = Exact<{ - test?: unknown | null; + test?: unknown | null | undefined; }>; @@ -3019,7 +3019,7 @@ export type Q2Query = { search: Array< expect(content).toMatchInlineSnapshot(` "export type UsersQueryVariables = Exact<{ - reverse?: boolean | null; + reverse?: boolean | null | undefined; }>; @@ -4969,8 +4969,8 @@ function test(q: GetEntityBrandDataQuery): void { expect(content).toMatchInlineSnapshot(` "export type UserQueryVariables = Exact<{ - testArray?: Array | string | null; - requireString: Array | string; + testArray?: Array | string | null | undefined; + requireString: Array | string; innerRequired: Array | string; }>; @@ -5009,8 +5009,8 @@ function test(q: GetEntityBrandDataQuery): void { expect(content).toMatchInlineSnapshot(` "export type UserQueryVariables = Exact<{ - testArray?: Array | null; - requireString: Array; + testArray?: Array | null | undefined; + requireString: Array; innerRequired: Array; }>; diff --git a/packages/plugins/typescript/operations/tests/ts-documents.standalone.default-scalar-types.spec.ts b/packages/plugins/typescript/operations/tests/ts-documents.standalone.default-scalar-types.spec.ts index bb55e79e7ea..ecb60c75d73 100644 --- a/packages/plugins/typescript/operations/tests/ts-documents.standalone.default-scalar-types.spec.ts +++ b/packages/plugins/typescript/operations/tests/ts-documents.standalone.default-scalar-types.spec.ts @@ -79,10 +79,10 @@ describe('TypeScript Operations Plugin - Default Scalar types', () => { export type UserQueryVariables = Exact<{ nonNullableDate: unknown; - nullableDate?: unknown | null; - dateArray1?: Array | unknown | null; - dateArray2: Array | unknown; - dateArray3?: Array | unknown | null; + nullableDate?: unknown | null | undefined; + dateArray1?: Array | unknown | null | undefined; + dateArray2: Array | unknown; + dateArray3?: Array | unknown | null | undefined; dateArray4: Array | unknown; input: UserInput; }>; @@ -172,10 +172,10 @@ describe('TypeScript Operations Plugin - Default Scalar types', () => { export type UserQueryVariables = Exact<{ nonNullableDate: any; - nullableDate?: any | null; - dateArray1?: Array | any | null; - dateArray2: Array | any; - dateArray3?: Array | any | null; + nullableDate?: any | null | undefined; + dateArray1?: Array | any | null | undefined; + dateArray2: Array | any; + dateArray3?: Array | any | null | undefined; dateArray4: Array | any; input: UserInput; }>; @@ -265,10 +265,10 @@ describe('TypeScript Operations Plugin - Default Scalar types', () => { export type UserQueryVariables = Exact<{ nonNullableDate: Date; - nullableDate?: Date | null; - dateArray1?: Array | Date | null; - dateArray2: Array | Date; - dateArray3?: Array | Date | null; + nullableDate?: Date | null | undefined; + dateArray1?: Array | Date | null | undefined; + dateArray2: Array | Date; + dateArray3?: Array | Date | null | undefined; dateArray4: Array | Date; input: UserInput; }>; diff --git a/packages/plugins/typescript/operations/tests/ts-documents.standalone.import-types.spec.ts b/packages/plugins/typescript/operations/tests/ts-documents.standalone.import-types.spec.ts index fd7f2687d21..7f09e1440d0 100644 --- a/packages/plugins/typescript/operations/tests/ts-documents.standalone.import-types.spec.ts +++ b/packages/plugins/typescript/operations/tests/ts-documents.standalone.import-types.spec.ts @@ -135,8 +135,8 @@ describe('TypeScript Operations Plugin - Import Types', () => { export type UsersWithScalarInputQueryVariables = Exact<{ from: unknown; - to?: unknown | null; - role?: TypeImport.UserRole | null; + to?: unknown | null | undefined; + role?: TypeImport.UserRole | null | undefined; }>; @@ -279,8 +279,8 @@ describe('TypeScript Operations Plugin - Import Types', () => { export type UsersWithScalarInputQueryVariables = Exact<{ from: unknown; - to?: unknown | null; - role?: TypeImport.UserRole | null; + to?: unknown | null | undefined; + role?: TypeImport.UserRole | null | undefined; }>; @@ -375,11 +375,11 @@ describe('TypeScript Operations Plugin - Import Types', () => { "type Exact = { [K in keyof T]: T[K] }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type UserQueryVariables = Exact<{ - id?: string | null; - name?: string | null; - bool?: boolean | null; - int?: number | null; - float?: number | null; + id?: string | null | undefined; + name?: string | null | undefined; + bool?: boolean | null | undefined; + int?: number | null | undefined; + float?: number | null | undefined; }>; diff --git a/packages/plugins/typescript/operations/tests/ts-documents.standalone.input.spec.ts b/packages/plugins/typescript/operations/tests/ts-documents.standalone.input.spec.ts index 3dc3b25f127..a67c55b8f09 100644 --- a/packages/plugins/typescript/operations/tests/ts-documents.standalone.input.spec.ts +++ b/packages/plugins/typescript/operations/tests/ts-documents.standalone.input.spec.ts @@ -10,17 +10,6 @@ describe('TypeScript Operations Plugin - Input', () => { users(input: UsersInput!, ageRange1: [Int], ageRange2: [Int]!, ageRange3: [Int!], ageRange4: [Int!]!): [User!]! } - type ResponseError { - error: ResponseErrorType! - } - - enum ResponseErrorType { - NOT_FOUND - INPUT_VALIDATION_ERROR - FORBIDDEN_ERROR - UNEXPECTED_ERROR - } - type User { id: ID! ageRange1: [Int] @@ -129,10 +118,10 @@ describe('TypeScript Operations Plugin - Input', () => { export type UsersWithScalarInputQueryVariables = Exact<{ inputNonNullable: UsersInput; - inputNullable?: UsersInput | null; - ageRange1?: Array | number | null; - ageRange2: Array | number; - ageRange3?: Array | number | null; + inputNullable?: UsersInput | null | undefined; + ageRange1?: Array | number | null | undefined; + ageRange2: Array | number; + ageRange3?: Array | number | null | undefined; ageRange4: Array | number; }>; @@ -150,17 +139,6 @@ describe('TypeScript Operations Plugin - Input', () => { users(input: UsersInput!): [User!]! } - type ResponseError { - error: ResponseErrorType! - } - - enum ResponseErrorType { - NOT_FOUND - INPUT_VALIDATION_ERROR - FORBIDDEN_ERROR - UNEXPECTED_ERROR - } - type User { id: ID! ageRange1: [Int] @@ -257,7 +235,7 @@ describe('TypeScript Operations Plugin - Input', () => { export type UsersWithScalarInputQueryVariables = Exact<{ inputNonNullable: UsersInput; - inputNullable?: UsersInput | null; + inputNullable?: UsersInput | null | undefined; }>; @@ -276,17 +254,6 @@ describe('TypeScript Operations Plugin - Input', () => { users(input: UsersInput!): [User!]! } - type ResponseError { - error: ResponseErrorType! - } - - enum ResponseErrorType { - NOT_FOUND - INPUT_VALIDATION_ERROR - FORBIDDEN_ERROR - UNEXPECTED_ERROR - } - type User { id: ID! ageRange1: [Int] @@ -374,7 +341,7 @@ describe('TypeScript Operations Plugin - Input', () => { export type UsersQueryVariables = Exact<{ inputNonNullable: UsersInput; - inputNullable?: UsersInput | null; + inputNullable?: UsersInput | null | undefined; }>; @@ -384,4 +351,101 @@ describe('TypeScript Operations Plugin - Input', () => { validateTs(result, undefined, undefined, undefined, undefined, true); }); + + it('generates with custom inputMaybeValue', async () => { + const schema = buildSchema(/* GraphQL */ ` + type Query { + user(input: UserInput!): User + } + + type User { + id: ID! + } + + input UserInput { + dateRange1: [DateTime] + dateRange2: [DateTime]! + dateRange3: [DateTime!] + dateRange4: [DateTime!]! + bestFriend: UserBestFriendInput + nestedInput: UserInput + } + + input UserBestFriendInput { + name: String + bestFriendDateRange1: [DateTime] + bestFriendDateRange2: [DateTime]! + bestFriendDateRange3: [DateTime!] + bestFriendDateRange4: [DateTime!]! + } + + scalar DateTime + `); + const document = parse(/* GraphQL */ ` + query Users( + $input: UserInput + $dateTime1: DateTime + $dateTime2: DateTime! + $dateTimeArray1: [DateTime] + $dateTimeArray2: [DateTime]! + $dateTimeArray3: [DateTime!] + $dateTimeArray4: [DateTime!]! + ) { + user { + __typename + } + } + `); + + const result = mergeOutputs([ + await plugin( + schema, + [{ document }], + { + inputMaybeValue: 'T | null', + scalars: { + DateTime: 'Date', + }, + }, + { outputFile: '' } + ), + ]); + + expect(result).toMatchInlineSnapshot(` + "type Exact = { [K in keyof T]: T[K] }; + export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; + type UserInput = { + dateRange1?: Array | null; + dateRange2: Array; + dateRange3?: Array | null; + dateRange4: Array; + bestFriend?: UserBestFriendInput | null; + nestedInput?: UserInput | null; + }; + + type UserBestFriendInput = { + name?: string | null; + bestFriendDateRange1?: Array | null; + bestFriendDateRange2: Array; + bestFriendDateRange3?: Array | null; + bestFriendDateRange4: Array; + }; + + export type UsersQueryVariables = Exact<{ + input?: UserInput | null; + dateTime1?: Date | null; + dateTime2: Date; + dateTimeArray1?: Array | Date | null; + dateTimeArray2: Array | Date; + dateTimeArray3?: Array | Date | null; + dateTimeArray4: Array | Date; + }>; + + + export type UsersQuery = { user: { __typename: 'User' } | null }; + " + `); + + validateTs(result, undefined, undefined, undefined, undefined, true); + }); }); diff --git a/packages/plugins/typescript/operations/tests/ts-documents.standalone.spec.ts b/packages/plugins/typescript/operations/tests/ts-documents.standalone.spec.ts index a4ce0116403..45f5fc3f578 100644 --- a/packages/plugins/typescript/operations/tests/ts-documents.standalone.spec.ts +++ b/packages/plugins/typescript/operations/tests/ts-documents.standalone.spec.ts @@ -163,8 +163,8 @@ describe('TypeScript Operations Plugin - Standalone', () => { export type UsersWithScalarInputQueryVariables = Exact<{ from: unknown; - to?: unknown | null; - role?: UserRole | null; + to?: unknown | null | undefined; + role?: UserRole | null | undefined; }>; diff --git a/packages/presets/client/tests/client-preset.enum.spec.ts b/packages/presets/client/tests/client-preset.enum.spec.ts index 3e55808d024..8ea0aa1a047 100644 --- a/packages/presets/client/tests/client-preset.enum.spec.ts +++ b/packages/presets/client/tests/client-preset.enum.spec.ts @@ -77,7 +77,7 @@ describe('client-preset - Enum', () => { | 'SQUARE'; export type ShapeQueryVariables = Exact<{ - shape?: Shape | null; + shape?: Shape | null | undefined; }>; @@ -198,7 +198,7 @@ describe('client-preset - Enum', () => { export type Shape = typeof Shape[keyof typeof Shape]; export type ShapeQueryVariables = Exact<{ - shape?: Shape | null; + shape?: Shape | null | undefined; }>;