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

Introduce dedupeFragments config flag for dealing with duplicate fragments #6018

Merged
merged 10 commits into from
Jun 20, 2021

Conversation

gilgardosh
Copy link
Collaborator

@gilgardosh gilgardosh commented May 18, 2021

Related #4684

@changeset-bot
Copy link

changeset-bot bot commented May 18, 2021

🦋 Changeset detected

Latest commit: 1c695e5

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

This PR includes changesets to release 34 packages
Name Type
@graphql-codegen/visitor-plugin-common Patch
@graphql-codegen/typed-document-node Patch
@graphql-codegen/flow Patch
@graphql-codegen/flow-operations Patch
@graphql-codegen/java-apollo-android Patch
@graphql-codegen/java Patch
@graphql-codegen/kotlin Patch
@graphql-codegen/java-resolvers Patch
@graphql-codegen/c-sharp-operations Patch
@graphql-codegen/c-sharp Patch
@graphql-codegen/typescript-apollo-angular Patch
@graphql-codegen/typescript-apollo-client-helpers Patch
@graphql-codegen/typescript-compatibility Patch
@graphql-codegen/typescript-document-nodes Patch
@graphql-codegen/typescript-generic-sdk Patch
@graphql-codegen/typescript-graphql-request Patch
@graphql-codegen/typescript-mongodb Patch
@graphql-codegen/typescript-oclif Patch
@graphql-codegen/typescript-operations Patch
@graphql-codegen/typescript-react-offix Patch
@graphql-codegen/typescript-react-apollo Patch
@graphql-codegen/typescript-react-query Patch
@graphql-codegen/typescript-resolvers Patch
@graphql-codegen/typescript-stencil-apollo Patch
@graphql-codegen/typescript-type-graphql Patch
@graphql-codegen/typescript Patch
@graphql-codegen/typescript-urql-graphcache Patch
@graphql-codegen/urql-svelte-operations-store Patch
@graphql-codegen/typescript-urql Patch
@graphql-codegen/typescript-vue-apollo Patch
@graphql-codegen/jsdoc Patch
@graphql-codegen/graphql-modules-preset Patch
@graphql-codegen/import-types-preset Patch
@graphql-codegen/near-operation-file-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

@theguild-bot
Copy link
Collaborator

theguild-bot commented May 18, 2021

The latest changes of this PR are not available as alpha, since there are no linked changesets for this PR.

@gilgardosh gilgardosh marked this pull request as ready for review May 19, 2021 09:14
@dotansimha
Copy link
Owner

Thoughts on that:

  1. I think while generating fragments DocuemntNode, we can flatten and remove ALL other fragments' definitions. So each fragment will be standalone, with just spreads for other fragments.
  2. Then, in each query DocumentNode that we generate, we can add all fragments in the query, and deduplicate it, based on the map of fragments.

Today

const fragmentB = `fragment B on B { ... }`;
const fragmentA = `fragment A on A { field { ...B } } ${fragmentB}`;
const query = `query { ...B, ...A } ${fragmentA} ${fragmentB}`

What I suggest, is to do:

const fragmentB = `fragment B on B { ... }`;
const fragmentA = `fragment A on A { field { ...B } }`; // No template literals here
const query = `query { ...B, ...A } ${fragmentA} ${fragmentB}` // Only here

@dotansimha dotansimha changed the title Duplicated nested fragments Introduce dedupeFragments config flag for dealing with duplicate fragments Jun 20, 2021
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.

None yet

3 participants