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

fragment not deduplicated by client preset #8670

Closed
saihaj opened this issue Dec 1, 2022 · 4 comments
Closed

fragment not deduplicated by client preset #8670

saihaj opened this issue Dec 1, 2022 · 4 comments
Labels
presets Related to Codegen presets stage/1-reproduction A reproduction exists

Comments

@saihaj
Copy link
Collaborator

saihaj commented Dec 1, 2022

Hey 👋 I have also encountered this issue, and it's a bit of a potential blocker so I'm hopeful we can resolve it. I've created a minimal repro here: https://codesandbox.io/s/focused-silence-flkogf

It is a very minimal repro but I think shows the essence of the issue. If you run npm run start, the GraphQL query is printed showing two instances of the example SharedComponentFragment fragments I included. This is essentially how my query looks when seeing the error at the network level There can only be one fragment named 'X', so hopefully serves as a suitable reproduction — let me know if not though!

Originally posted by @lrholmes in #8617 (reply in thread)

@saihaj saihaj added stage/1-reproduction A reproduction exists presets Related to Codegen presets labels Dec 1, 2022
@lrholmes
Copy link

lrholmes commented Dec 6, 2022

Thanks for creating this issue for us! I'm curious to ask if you have any pointers for how someone could start looking into diagnosing this issue? I've no experience contributing to this repo but this issue is becoming a bit of a blocker for me so am open to helping if I can 🙏

@saihaj
Copy link
Collaborator Author

saihaj commented Dec 6, 2022

Hey @lrholmes I started with a repro from the codesanbox to this #8671 I don't think we have a easy way to mock this.

But to fix the issue we just need to make the default to be true here

dedupeFragments: options.config.dedupeFragments,

@lrholmes
Copy link

lrholmes commented Dec 7, 2022

Ah amazing, sorry I missed your PR! Thanks for the pointer to this line of code, I noticed that we're currently able to override that at the codegen config level:

    'src/graphql/': {
      documents: ['src/**/*.tsx', '!src/graphql'],
      preset: 'client',
      plugins: [],
      presetConfig: {
        fragmentMasking: { unmaskFunctionName: 'getFragmentData' }
      },
      config: {
        dedupeFragments: true, // <- added this and it works 🎉
      }
    },

Curious if this is could be helped by documentation, as looking at: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#config-api it wasn't clear to me we had the option of applying these additional config overrides.

@beerose
Copy link
Contributor

beerose commented Mar 7, 2023

Fixed in #8971

@beerose beerose closed this as completed Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
presets Related to Codegen presets stage/1-reproduction A reproduction exists
Projects
None yet
Development

No branches or pull requests

3 participants