Skip to content

Non-all field merging causes selection set initializer to stop being generated for local cache mutations #3554

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

Open
calvincestari opened this issue May 9, 2025 · 0 comments · May be fixed by apollographql/apollo-ios-dev#654
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation

Comments

@calvincestari
Copy link
Member

Summary

This is unintentional behaviour from the field merging work (#431).

extension ApolloCodegenConfiguration {
  /// Determine whether the operations files are output to the schema types module.
  func shouldGenerateSelectionSetInitializers(for operation: IR.Operation) -> Bool {
    guard experimentalFeatures.fieldMerging == .all else { return false }

    if operation.definition.isLocalCacheMutation {
      return true

    } else if options.selectionSetInitializers.contains(.operations) {
      return true

    } else {
      return options.selectionSetInitializers.contains(definitionNamed: operation.definition.name)
    }
  }

  /// Determine whether the operations files are output to the schema types module.
  func shouldGenerateSelectionSetInitializers(for fragment: IR.NamedFragment) -> Bool {
    guard experimentalFeatures.fieldMerging == .all else { return false }

    if options.selectionSetInitializers.contains(.namedFragments) { return true }

    if fragment.definition.isLocalCacheMutation {
      return true
    }

    return options.selectionSetInitializers.contains(definitionNamed: fragment.definition.name)
  }
}

Version

1.21.0

Steps to reproduce the behavior

Use a field merging configuration value of anything other than all in combination with local cache mutations.

Logs

Anything else?

No response

@calvincestari calvincestari added bug Generally incorrect behavior needs investigation labels May 9, 2025
@calvincestari calvincestari self-assigned this May 9, 2025
@calvincestari calvincestari added codegen Issues related to or arising from code generation and removed needs investigation labels May 9, 2025
@calvincestari calvincestari added this to the Patch Releases (1.x.x) milestone May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant