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

Keep fields specified by @unmask for use with Apollo Client data masking #10163

Merged

Conversation

jerelmiller
Copy link
Contributor

@jerelmiller jerelmiller commented Oct 4, 2024

Description

Provide support for @unmask with inlineFragmentTypes: "mask" so that these fields are available in the TypeScript type. This provides compatibility with Apollo Client's data masking feature that will be released in the upcoming 3.12 release.

Related #10162
Related apollographql/apollo-client#12085

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
    expected)

Screenshots/Sandbox (if appropriate/relevant):

See the data masking RFC for more details on the feature in Apollo Client.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added unit tests

Test Environment:

  • OS:
  • @graphql-codegen/...:
  • NodeJS:

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

Further comments

I'm opening this as a draft to discuss the idea with the maintainers. This is a continuation of our conversation in Slack 🙂.

Copy link

changeset-bot bot commented Oct 4, 2024

🦋 Changeset detected

Latest commit: 5035012

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

This PR includes changesets to release 9 packages
Name Type
@graphql-codegen/visitor-plugin-common Minor
@graphql-codegen/typescript-operations Minor
@graphql-codegen/typescript-document-nodes Patch
@graphql-codegen/gql-tag-operations Patch
@graphql-codegen/typescript-resolvers Patch
@graphql-codegen/typed-document-node Patch
@graphql-codegen/typescript Patch
@graphql-codegen/graphql-modules-preset Patch
@graphql-codegen/client-preset 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

@jerelmiller jerelmiller changed the title Keep fields specified by @unmask for use with Apollo Client data masking Keep fields specified by @unmask for use with Apollo Client data masking Oct 4, 2024
Comment on lines 604 to 606
if (!selectionNode.fragmentDirectives?.some(d => d.name.value === 'unmask')) {
continue;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What should happen if inlineFragmentTypes='combine' is used with @unmask?
Should we just target the 'mask' scenario in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think so. mask is the only one that removes fields from generated type correct?

I can probably be a bit more explicit here if need be that this should only be combined with unmask.

@eddeee888
Copy link
Collaborator

Should we update the doc for inlineFragmentTypes to mention the mask option and how it might interact with Apollo's @unmask?

* @description Whether fragment types should be inlined into other operations.
* "inline" is the default behavior and will perform deep inlining fragment types within operation type definitions.
* "combine" is the previous behavior that uses fragment type references without inlining the types (and might cause issues with deeply nested fragment that uses list types).
*

@eddeee888
Copy link
Collaborator

Could you please run yarn changeset and follow the prompts?
It'd publish an alpha version once that file is committed and pushed.

@jerelmiller
Copy link
Contributor Author

Should we update the doc for inlineFragmentTypes to mention the mask option and how it might interact with Apollo's @unmask?

Yes definitely! I'll add that change as well.

@jerelmiller jerelmiller marked this pull request as ready for review November 4, 2024 20:02
* };
* export default config;
*/
customDirectives?: CustomDirectivesConfig;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the new config option to enable the new apolloUnmask directive. Let me know if there is a better place for these.

@jerelmiller jerelmiller requested a review from eddeee888 November 4, 2024 20:06
@jerelmiller
Copy link
Contributor Author

@eddeee888 apologies for taking so long to get back to this! I'm finally back from all my conference travel and vacation. This should be ready to go on my end so please let me know if anything else needs tweaked. I'm holding off on the support for @deprecated with @unmask(mode: "migrate") for now and hope to come back to it. At this point though I think its a bit more work than I anticipated (happy to be proven wrong) and its far less important than having support for @unmask on its own.

Looking forward to landing this sometime soon!

@eddeee888
Copy link
Collaborator

eddeee888 commented Nov 12, 2024

Hi @jerelmiller , could you help fix this prettier issue? https://github.com/dotansimha/graphql-code-generator/actions/runs/11671752015/job/32751535165?pr=10163#step:4:11

We are very close to done, thank you for pushing it forward!

@jerelmiller
Copy link
Contributor Author

@eddeee888 got the prettier issue fixed in 5035012. I think that should be the last thing missing. Thanks for reviewing! Looking forward to having this in there 🙂

@eddeee888 eddeee888 merged commit fa64fbf into dotansimha:master Nov 13, 2024
18 checks passed
@jerelmiller jerelmiller deleted the jerel/apollo-fragment-masking branch November 13, 2024 15:42
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.

3 participants