Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/breezy-games-enter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@graphql-codegen/visitor-plugin-common': major
'@graphql-codegen/typescript-operations': major
'@graphql-codegen/client-preset': major
---

Fix nullable field optionality in operations

Previously, a nullable Result field is generated as optional (marked by `?` TypeScript modifier) by default. This is not correct, because generally at runtime such field can only be `null`, and not `undefined` (both missing from the object OR `undefined`). The only exceptions are when fields are deferred (using `@defer` directive) or marked as conditional (using `@skip` or `@include`).

Now, a nullable Result field cannot be optional unless the exceptions are met. This also limits `avoidOptionals` to only target Variables input, since some users may want to force explicit `null` when providing operation variables.
38 changes: 19 additions & 19 deletions dev-test/githunt/typed-document-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type OnCommentAddedSubscriptionVariables = Exact<{

export type OnCommentAddedSubscription = {
__typename?: 'Subscription';
commentAdded?: {
commentAdded: {
__typename?: 'Comment';
id: number;
createdAt: number;
Expand All @@ -24,8 +24,8 @@ export type CommentQueryVariables = Exact<{

export type CommentQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string; html_url: string } | null;
entry?: {
currentUser: { __typename?: 'User'; login: string; html_url: string } | null;
entry: {
__typename?: 'Entry';
id: number;
createdAt: number;
Expand All @@ -40,8 +40,8 @@ export type CommentQuery = {
} | null>;
repository: {
__typename?: 'Repository';
description?: string | null;
open_issues_count?: number | null;
description: string | null;
open_issues_count: number | null;
stargazers_count: number;
full_name: string;
html_url: string;
Expand All @@ -61,7 +61,7 @@ export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }

export type CurrentUserForProfileQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string; avatar_url: string } | null;
currentUser: { __typename?: 'User'; login: string; avatar_url: string } | null;
};

export type FeedEntryFragment = {
Expand All @@ -74,10 +74,10 @@ export type FeedEntryFragment = {
__typename?: 'Repository';
full_name: string;
html_url: string;
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
owner?: { __typename?: 'User'; avatar_url: string } | null;
open_issues_count: number | null;
owner: { __typename?: 'User'; avatar_url: string } | null;
};
vote: { __typename?: 'Vote'; vote_value: number };
postedBy: { __typename?: 'User'; html_url: string; login: string };
Expand All @@ -91,8 +91,8 @@ export type FeedQueryVariables = Exact<{

export type FeedQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string } | null;
feed?: Array<{
currentUser: { __typename?: 'User'; login: string } | null;
feed: Array<{
__typename?: 'Entry';
id: number;
commentCount: number;
Expand All @@ -102,10 +102,10 @@ export type FeedQuery = {
__typename?: 'Repository';
full_name: string;
html_url: string;
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
owner?: { __typename?: 'User'; avatar_url: string } | null;
open_issues_count: number | null;
owner: { __typename?: 'User'; avatar_url: string } | null;
};
vote: { __typename?: 'Vote'; vote_value: number };
postedBy: { __typename?: 'User'; html_url: string; login: string };
Expand All @@ -118,17 +118,17 @@ export type SubmitRepositoryMutationVariables = Exact<{

export type SubmitRepositoryMutation = {
__typename?: 'Mutation';
submitRepository?: { __typename?: 'Entry'; createdAt: number } | null;
submitRepository: { __typename?: 'Entry'; createdAt: number } | null;
};

export type RepoInfoFragment = {
__typename?: 'Entry';
createdAt: number;
repository: {
__typename?: 'Repository';
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
open_issues_count: number | null;
};
postedBy: { __typename?: 'User'; html_url: string; login: string };
};
Expand All @@ -140,7 +140,7 @@ export type SubmitCommentMutationVariables = Exact<{

export type SubmitCommentMutation = {
__typename?: 'Mutation';
submitComment?: {
submitComment: {
__typename?: 'Comment';
id: number;
createdAt: number;
Expand All @@ -162,7 +162,7 @@ export type VoteMutationVariables = Exact<{

export type VoteMutation = {
__typename?: 'Mutation';
vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null;
vote: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null;
};

export const CommentsPageCommentFragmentDoc = {
Expand Down
38 changes: 19 additions & 19 deletions dev-test/githunt/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type OnCommentAddedSubscriptionVariables = Exact<{

export type OnCommentAddedSubscription = {
__typename?: 'Subscription';
commentAdded?: {
commentAdded: {
__typename?: 'Comment';
id: number;
createdAt: number;
Expand All @@ -23,8 +23,8 @@ export type CommentQueryVariables = Exact<{

export type CommentQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string; html_url: string } | null;
entry?: {
currentUser: { __typename?: 'User'; login: string; html_url: string } | null;
entry: {
__typename?: 'Entry';
id: number;
createdAt: number;
Expand All @@ -39,8 +39,8 @@ export type CommentQuery = {
} | null>;
repository: {
__typename?: 'Repository';
description?: string | null;
open_issues_count?: number | null;
description: string | null;
open_issues_count: number | null;
stargazers_count: number;
full_name: string;
html_url: string;
Expand All @@ -60,7 +60,7 @@ export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }

export type CurrentUserForProfileQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string; avatar_url: string } | null;
currentUser: { __typename?: 'User'; login: string; avatar_url: string } | null;
};

export type FeedEntryFragment = {
Expand All @@ -73,10 +73,10 @@ export type FeedEntryFragment = {
__typename?: 'Repository';
full_name: string;
html_url: string;
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
owner?: { __typename?: 'User'; avatar_url: string } | null;
open_issues_count: number | null;
owner: { __typename?: 'User'; avatar_url: string } | null;
};
vote: { __typename?: 'Vote'; vote_value: number };
postedBy: { __typename?: 'User'; html_url: string; login: string };
Expand All @@ -90,8 +90,8 @@ export type FeedQueryVariables = Exact<{

export type FeedQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string } | null;
feed?: Array<{
currentUser: { __typename?: 'User'; login: string } | null;
feed: Array<{
__typename?: 'Entry';
id: number;
commentCount: number;
Expand All @@ -101,10 +101,10 @@ export type FeedQuery = {
__typename?: 'Repository';
full_name: string;
html_url: string;
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
owner?: { __typename?: 'User'; avatar_url: string } | null;
open_issues_count: number | null;
owner: { __typename?: 'User'; avatar_url: string } | null;
};
vote: { __typename?: 'Vote'; vote_value: number };
postedBy: { __typename?: 'User'; html_url: string; login: string };
Expand All @@ -117,17 +117,17 @@ export type SubmitRepositoryMutationVariables = Exact<{

export type SubmitRepositoryMutation = {
__typename?: 'Mutation';
submitRepository?: { __typename?: 'Entry'; createdAt: number } | null;
submitRepository: { __typename?: 'Entry'; createdAt: number } | null;
};

export type RepoInfoFragment = {
__typename?: 'Entry';
createdAt: number;
repository: {
__typename?: 'Repository';
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
open_issues_count: number | null;
};
postedBy: { __typename?: 'User'; html_url: string; login: string };
};
Expand All @@ -139,7 +139,7 @@ export type SubmitCommentMutationVariables = Exact<{

export type SubmitCommentMutation = {
__typename?: 'Mutation';
submitComment?: {
submitComment: {
__typename?: 'Comment';
id: number;
createdAt: number;
Expand All @@ -161,5 +161,5 @@ export type VoteMutationVariables = Exact<{

export type VoteMutation = {
__typename?: 'Mutation';
vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null;
vote: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null;
};
38 changes: 19 additions & 19 deletions dev-test/githunt/types.enumsAsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type OnCommentAddedSubscriptionVariables = Exact<{

export type OnCommentAddedSubscription = {
__typename?: 'Subscription';
commentAdded?: {
commentAdded: {
__typename?: 'Comment';
id: number;
createdAt: number;
Expand All @@ -23,8 +23,8 @@ export type CommentQueryVariables = Exact<{

export type CommentQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string; html_url: string } | null;
entry?: {
currentUser: { __typename?: 'User'; login: string; html_url: string } | null;
entry: {
__typename?: 'Entry';
id: number;
createdAt: number;
Expand All @@ -39,8 +39,8 @@ export type CommentQuery = {
} | null>;
repository: {
__typename?: 'Repository';
description?: string | null;
open_issues_count?: number | null;
description: string | null;
open_issues_count: number | null;
stargazers_count: number;
full_name: string;
html_url: string;
Expand All @@ -60,7 +60,7 @@ export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }

export type CurrentUserForProfileQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string; avatar_url: string } | null;
currentUser: { __typename?: 'User'; login: string; avatar_url: string } | null;
};

export type FeedEntryFragment = {
Expand All @@ -73,10 +73,10 @@ export type FeedEntryFragment = {
__typename?: 'Repository';
full_name: string;
html_url: string;
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
owner?: { __typename?: 'User'; avatar_url: string } | null;
open_issues_count: number | null;
owner: { __typename?: 'User'; avatar_url: string } | null;
};
vote: { __typename?: 'Vote'; vote_value: number };
postedBy: { __typename?: 'User'; html_url: string; login: string };
Expand All @@ -90,8 +90,8 @@ export type FeedQueryVariables = Exact<{

export type FeedQuery = {
__typename?: 'Query';
currentUser?: { __typename?: 'User'; login: string } | null;
feed?: Array<{
currentUser: { __typename?: 'User'; login: string } | null;
feed: Array<{
__typename?: 'Entry';
id: number;
commentCount: number;
Expand All @@ -101,10 +101,10 @@ export type FeedQuery = {
__typename?: 'Repository';
full_name: string;
html_url: string;
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
owner?: { __typename?: 'User'; avatar_url: string } | null;
open_issues_count: number | null;
owner: { __typename?: 'User'; avatar_url: string } | null;
};
vote: { __typename?: 'Vote'; vote_value: number };
postedBy: { __typename?: 'User'; html_url: string; login: string };
Expand All @@ -117,17 +117,17 @@ export type SubmitRepositoryMutationVariables = Exact<{

export type SubmitRepositoryMutation = {
__typename?: 'Mutation';
submitRepository?: { __typename?: 'Entry'; createdAt: number } | null;
submitRepository: { __typename?: 'Entry'; createdAt: number } | null;
};

export type RepoInfoFragment = {
__typename?: 'Entry';
createdAt: number;
repository: {
__typename?: 'Repository';
description?: string | null;
description: string | null;
stargazers_count: number;
open_issues_count?: number | null;
open_issues_count: number | null;
};
postedBy: { __typename?: 'User'; html_url: string; login: string };
};
Expand All @@ -139,7 +139,7 @@ export type SubmitCommentMutationVariables = Exact<{

export type SubmitCommentMutation = {
__typename?: 'Mutation';
submitComment?: {
submitComment: {
__typename?: 'Comment';
id: number;
createdAt: number;
Expand All @@ -161,5 +161,5 @@ export type VoteMutationVariables = Exact<{

export type VoteMutation = {
__typename?: 'Mutation';
vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null;
vote: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null;
};
Loading