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

Leave TData alone in Unmasked if it does not contain fragment refs #12267

Merged
merged 6 commits into from
Jan 14, 2025

Conversation

jerelmiller
Copy link
Member

Partially fixes #12266

Moves the ContainsFragmentRefs check from MaybeMasked to the Unmasked type to leave TData alone when TData does not contain fragment refs.

We will still need a solution that works after masked types are generated for situations like #12266.

@jerelmiller jerelmiller requested a review from phryneas January 13, 2025 17:39
Copy link

changeset-bot bot commented Jan 13, 2025

🦋 Changeset detected

Latest commit: 213bcb1

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

This PR includes changesets to release 1 package
Name Type
@apollo/client 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

@svc-apollo-docs
Copy link

svc-apollo-docs commented Jan 13, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 672bbfe98bb926888f96a559

Copy link

pkg-pr-new bot commented Jan 13, 2025

npm i https://pkg.pr.new/@apollo/client@12267

commit: 213bcb1

Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 213bcb1
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67855350e585af0008a92c84
😎 Deploy Preview https://deploy-preview-12267--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Jan 13, 2025

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 40.66 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 50.07 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.18 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.18 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.58 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.26 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.24 KB (0%)
import { useQuery } from "dist/react/index.js" 5.21 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.29 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.7 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.78 KB (0%)
import { useMutation } from "dist/react/index.js" 3.62 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.84 KB (0%)
import { useSubscription } from "dist/react/index.js" 4.42 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 3.48 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.51 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.17 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 5.01 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.66 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.09 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.74 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.41 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.35 KB (0%)
import { useFragment } from "dist/react/index.js" 2.36 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.31 KB (0%)

@jerelmiller jerelmiller changed the title Jerel/unmasked fragment refs type Leave TData alone in Unmasked if it does not contain fragment refs Jan 13, 2025
@jerelmiller
Copy link
Member Author

My thoughts on handling the case where scalars are generated as tagged types:

We should probably check to see if the value of the key extends a primitive and leave the type alone if so. We have this branch in UnwrapFragmentRefs:

    : TData extends object ?
      {
        [K in keyof TData]: UnwrapFragmentRefs<TData[K]>;
      }

Using a tagged type (i.e. Tagged<string> which results in a type of string & { ... }) passes this check since it is an object. If we first check if the value is a primitive, I believe we can handle the case where these tagged types are used as scalar values with masked types.

// where `Primitive` is our `Primitive` type in src/utilities/types/Primitive.ts
TData extends Primitive ? TData : // ...

Copy link
Member

@phryneas phryneas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good plan to me.

@github-actions github-actions bot added the auto-cleanup 🤖 label Jan 14, 2025
@DmitryMasley
Copy link

Hi. This ts-ignore was introduced with Unmasked type.


In the bundle, it actually produces the error

          Type 'Unmasked<sub-TData>' is not assignable to type 'Unmasked<super-TData>'.
            Type 'sub-TData | (sub-TData extends object ? UnwrapFragmentRefs<RemoveMaskedMarker<RemoveFragmentName<sub-TData>>> : sub-TData)' is not assignable to type 'Unmasked<super-TData>'.
              Type 'sub-TData' is not assignable to type 'Unmasked<super-TData>'.
                Type 'super-TData' is not assignable to type 'Unmasked<super-TData>'.

11 export interface MockedResponse<out TData = Record<string, any>, out TVariables = Record<string, any>> {

@jerelmiller
Copy link
Member Author

@DmitryMasley are you saying that this PR introduces this error, or that this error already exists in published versions? If the latter, can you open a new issue for that?

@DmitryMasley
Copy link

DmitryMasley commented Jan 14, 2025

@DmitryMasley are you saying that this PR introduces this error, or that this error already exists in published versions? If the latter, can you open a new issue for that?

It already exists in the main branch. In the source code, it appears the error is suppressed, but when @apollo/client is installed it produces this error.

@DmitryMasley
Copy link

Gonna fill the issue, though it may be connected, since the issue is caused by Unmasked type.

@jerelmiller jerelmiller merged commit d57429d into main Jan 14, 2025
48 checks passed
@jerelmiller jerelmiller deleted the jerel/unmasked-fragment-refs-type branch January 14, 2025 17:07
@github-actions github-actions bot mentioned this pull request Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unmasked breaks when using Tagged type
4 participants