-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
stage/0-issue-prerequisitesNeeds more information before we can start working on itNeeds more information before we can start working on it
Description
Which packages are impacted by your issue?
@graphql-codegen/typescript
Describe the bug
Since #3836 fields adorned with @include or @skip directives are correctly treated as optional:
query getUsers($includeName: Boolean!) {
users {
id
name @include(if: $includeName)
}
}becomes
export type GetUsersQuery = (
{ users: Array<(
{ id: string, name?: string }
& { __typename?: 'User' }
)> }
& { __typename?: 'Query' }
);However, when the conditional field is aliased, it's treated as mandatory:
query getUsers($includeName: Boolean!) {
users {
id
userName: name @include(if: $includeName)
}
}becomes
export type GetUsersQuery = (
{ users: Array<(
{ id: string, userName: string } // no question mark in sight
& { __typename?: 'User' }
)> }
& { __typename?: 'Query' }
);Your Example Website or App
Steps to Reproduce the Bug or Issue
Alias a conditional field (i.e. one with @include or @skip directive). It's no longer treated as optional in the generated type.
Expected behavior
Fields adorned with @include or @skip should be treated as optional in the generated type, even if they are aliased.
Screenshots or Videos
No response
Platform
-
Codegen Config File
No response
Additional context
No response
radarfox and ValentinHmdugue
Metadata
Metadata
Assignees
Labels
stage/0-issue-prerequisitesNeeds more information before we can start working on itNeeds more information before we can start working on it