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

[Data masking] Ensure null is retained when unmasking nullable objects #12133

Merged
merged 7 commits into from
Nov 15, 2024

Conversation

jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Nov 15, 2024

The Unmasked helper has a bug where unmasking a nullable object would return the object as a non-null type. This PR ensures the null is retained in the type.

@svc-apollo-docs
Copy link

svc-apollo-docs commented Nov 15, 2024

✅ Docs Preview Ready

No new or changed pages found.

Copy link

changeset-bot bot commented Nov 15, 2024

🦋 Changeset detected

Latest commit: 07b38d5

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

Copy link

pkg-pr-new bot commented Nov 15, 2024

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

commit: 07b38d5

@jerelmiller jerelmiller added auto-cleanup 🤖 🎭 data-masking Issues/PRs related to data masking labels Nov 15, 2024
@jerelmiller jerelmiller added this to the Data masking milestone Nov 15, 2024
} & CombineFragmentRefs<FragmentRefs>
>
: never
null extends TData ?
Copy link
Member

@phryneas phryneas Nov 15, 2024

Choose a reason for hiding this comment

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

It doesn't let me apply a suggestion here, but as an alternative, you could also distribute over TData:

This is the change to the original type:

export type UnwrapFragmentRefs<TData> =
+  TData extends any ?
    // Leave TData alone if it is Record<string, any> and not a specific shape
    string extends keyof NonNullable<TData> ? TData
    : " $fragmentRefs" extends keyof NonNullable<TData> ?
      TData extends { " $fragmentRefs"?: infer FragmentRefs extends object } ?
        Prettify<
          {
            [K in keyof TData as K extends " $fragmentRefs" ? never
            : K]: UnwrapFragmentRefs<TData[K]>;
          } & CombineFragmentRefs<FragmentRefs>
        >
      : never
    : TData extends object ?
      { [K in keyof TData]: UnwrapFragmentRefs<TData[K]> }
    : TData
+  : never;

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes I like that much better! Updated in ba2cb2c

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.

Either way, this fixes a real bug - approved :)

@jerelmiller jerelmiller force-pushed the jerel/allow-null-in-usefragment branch from 94e0f01 to f30d83c Compare November 15, 2024 17:31
Base automatically changed from jerel/allow-null-in-usefragment to release-3.12 November 15, 2024 17:37
Copy link
Contributor

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 40.63 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 51.03 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.58 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.32 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.55 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.3 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.71 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.85 KB (0%)
import { useSubscription } from "dist/react/index.js" 4.43 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.42 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.36 KB (0%)
import { useFragment } from "dist/react/index.js" 2.37 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.31 KB (0%)

@jerelmiller jerelmiller merged commit a6ece37 into release-3.12 Nov 15, 2024
41 of 45 checks passed
@jerelmiller jerelmiller deleted the jerel/fix-nested-null branch November 15, 2024 17:42
@github-actions github-actions bot mentioned this pull request Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-cleanup 🤖 🎭 data-masking Issues/PRs related to data masking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants