Skip to content

Aliased fields with @include/@skip are treated as mandatoryΒ #9745

@RadovanBednar

Description

@RadovanBednar

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

Metadata

Metadata

Assignees

Labels

stage/0-issue-prerequisitesNeeds more information before we can start working on it

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions