Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typescript-react-apollo): fix the type returned by useSuspenseQuery #878

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nekocode
Copy link

@nekocode nekocode commented Oct 26, 2024

This PR adds overload signatures to the generated useSuspenseQuery hooks to distinguish whether the parameter skipToken is passed. If the passed value is not skipToken, return non-nullable data. Example:

// @ts-ignore   <--- Force ignore "This overload signature is not compatible with its implementation signature"
export function useGetUserSuspenseQuery(
  baseOptions?: Apollo.SuspenseQueryHookOptions<
    Types.GetUserQuery,
    Types.GetUserQueryVariables
  >,
): Apollo.UseSuspenseQueryResult<
  Types.GetUserQuery, // Return non-nullable type
  Types.GetUserQueryVariables
>;

export function useGetUserSuspenseQuery(
  baseOptions?:
    | Apollo.SkipToken
    | Apollo.SuspenseQueryHookOptions<
        Types.GetUserQuery,
        Types.GetUserQueryVariables
      >,
): Apollo.UseSuspenseQueryResult<
  Types.GetUserQuery | undefined, // Otherwise return nullable type
  Types.GetUserQueryVariables
>;

export function useGetUserSuspenseQuery(
  baseOptions?:
    | Apollo.SkipToken
    | Apollo.SuspenseQueryHookOptions<
        Types.GetUserQuery,
        Types.GetUserQueryVariables
      >,
) {
  const options =
    baseOptions === Apollo.skipToken
      ? baseOptions
      : { ...defaultOptions, ...baseOptions };
  return Apollo.useSuspenseQuery<
    Types.GetUserQuery,
    Types.GetUserQueryVariables
  >(GetUserDocument, options);
}

Description

Please include a summary of the change and which issue is fixed. Please also include relevant
motivation and context. List any dependencies that are required for this change.

Related #838

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • This change requires a documentation update

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link

changeset-bot bot commented Oct 26, 2024

🦋 Changeset detected

Latest commit: 959c5cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/typescript-react-apollo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@eltonio450
Copy link

definitively needed, thank you for this 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants