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

apolloUnmask in client preset #10245

Open
16patsle opened this issue Jan 16, 2025 · 1 comment
Open

apolloUnmask in client preset #10245

16patsle opened this issue Jan 16, 2025 · 1 comment
Labels
waiting-for-answer Waiting for answer from author

Comments

@16patsle
Copy link

16patsle commented Jan 16, 2025

Which packages are impacted by your issue?

@graphql-codegen/client-preset

Describe the bug

In @graphql-codegen/typescript-operations version 4.4.0, support for the @unmask directive from Apollo's data masking was added. This requires settings inlineFragmentTypes: "mask" and customDirectives: { apolloUnmask: true } in the config, and seems to work as expected. However, @graphql-codegen/client-preset (version 4.5.1) does not seem to support this. Apollo's docs suggest to set customDirectives in presetConfig, but neither config nor presetConfig seems to work for this combination.

Your Example Website or App

https://stackblitz.com/edit/16patsle-codegen-apollo-unmask

Steps to Reproduce the Bug or Issue

  1. Set up codegen to support Apollo data masking (like in the example)
  2. Have a query with a fragment and @unmask
  3. Find the generated type for the Query
  4. Notice how it does not include the fields from the fragment, despite the @unmask directive
export type AllPostsQueryQuery = { __typename?: 'Query', allPost: Array<(
    { __typename?: 'Post', id: string }
    & { ' $fragmentRefs'?: { 'PostFragmentFragment': PostFragmentFragment } }
  ) | null> };

Expected behavior

I would expect the @unmask directive to work and give output similar to this:

export type AllPostsQueryQuery = { __typename?: 'Query', allPost: Array<(
    { __typename?: 'Post', id: string, title: string, excerpt?: string | null }
    & { ' $fragmentRefs'?: { 'PostFragmentFragment': PostFragmentFragment } }
  )> };

Notice that this includes other fields that are present in the PostFragment fragment in the example code

I guess the current behavior is in one way be expected given that customDirectives is not one of the options forwarded by client-preset. However, I think it would be desired for the client-preset to support customDirectives, and it does indeed work if I add customDirectives to forwardedConfig in the preset code.

Screenshots or Videos

No response

Platform

Codegen Config File

No response

Additional context

No response

@eddeee888
Copy link
Collaborator

Hi @16patsle, could you please try this alpha version:

@graphql-codegen/client-preset@4.6.0-alpha-20250122114357-7c7e465bb08931989482cd25adace26a27e143df

With the following config (slightly different from Apollo's doc):

presetConfig: { fragmentMasking: false },
config: {
  inlineFragmentTypes: 'mask',
  customDirectives: { apolloUnmask: true }, // this is in `config`, instead of `presetConfig` like the doc
},

@eddeee888 eddeee888 added the waiting-for-answer Waiting for answer from author label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-answer Waiting for answer from author
Projects
None yet
Development

No branches or pull requests

2 participants