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

OPERATION_BASED_WITH_INTERFACES fragment's name clash #4422

Open
chalermpong opened this issue Sep 30, 2022 · 1 comment
Open

OPERATION_BASED_WITH_INTERFACES fragment's name clash #4422

chalermpong opened this issue Sep 30, 2022 · 1 comment
Labels
🐛 Type: Bug 🧊 Icebox Features that would be nice but probably won't happen in the near future ⚠️ Breaking Change To be done in next major version

Comments

@chalermpong
Copy link
Contributor

Summary

With experimental_operationBasedWithInterfaces codegen model, fragment's name clash can happen with the example below. This problem is also exist in responseBased codegen model.

Version

3.6.1-SNAPSHOT

Steps to reproduce the behavior

Use this graphql:

query TestOperation {
  animal {
    ... AnimalFragment
  }
}
fragment AnimalFragment on Animal {
  species
  ... on Lion {
    ... LionAnimalFragment
  }
}
fragment LionAnimalFragment on Lion {
  temperature
}

For experimental_operationBasedWithInterfaces, output code will have two LionAnimalFragment classes:

// From typeset model for AnimalFragment
public data class LionAnimalFragment(
  public override val __typename: String,
  public override val species: String,
  /**
   * Synthetic field for inline fragment on Lion
   */
  public override val onLion: AnimalFragment.OnLion,
) : AnimalFragment

// From LionAnimalFragment
public data class LionAnimalFragment(
  public val temperature: Int,
) : Fragment.Data

For responseBased, output code will have two LionAnimalFragment:

public interface LionAnimalFragment : AnimalFragment, LionAnimalFragment {
  public override val __typename: String

  public override val species: String

  public override val temperature: Int
}

public interface LionAnimalFragment {
  public val temperature: Int
}
@martinbonnin
Copy link
Contributor

martinbonnin commented Sep 30, 2022

Good catch. We could nest the fragment classes in their interface (which is guaranteed to be unique because we don't allow 2 fragments with the same name)

interface AnimalFragment {
  class LionAnimalFragment: AnimalFragment
}

interface LionAnimalFragment

But that's a breaking change so for now I'd recommend to rename the fragment if that ever happens.

@martinbonnin martinbonnin added the ⚠️ Breaking Change To be done in next major version label Oct 3, 2022
@martinbonnin martinbonnin added the 🧊 Icebox Features that would be nice but probably won't happen in the near future label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Type: Bug 🧊 Icebox Features that would be nice but probably won't happen in the near future ⚠️ Breaking Change To be done in next major version
Projects
None yet
Development

No branches or pull requests

2 participants