Skip to content

Add omit_unreferenced_implementations config option (#416)#419

Open
WillAbides wants to merge 12 commits into
Khan:mainfrom
WillAbides:willabides/omit-unreferenced-implementations
Open

Add omit_unreferenced_implementations config option (#416)#419
WillAbides wants to merge 12 commits into
Khan:mainfrom
WillAbides:willabides/omit-unreferenced-implementations

Conversation

@WillAbides
Copy link
Copy Markdown

@WillAbides WillAbides commented May 25, 2026

Closes #416

Adds an opt-in omit_unreferenced_implementations config option that collapses unfragmented interface/union implementations into a single catch-all struct per interface selection.

With omit_unreferenced_implementations: true:

  • Per-type structs are generated only for implementations actually referenced via an inline or named fragment in the selection set.
  • A single catch-all struct <…>GenqlientOther is generated for each interface/union selection. It carries the interface's shared fields and satisfies the generated Go interface like any other impl. I chose the "GenqlientOther" suffix because it is very unlikely to be used in a real query.
  • Defaults to false for backward compatibility.

Tests

  • Snapshot tests for the inline-fragment, named-fragment-on-interface, named-fragment-on-concrete-type, union, abstract-fragment-spread-inside-concrete-inline-fragment, and all-impls-collapse cases. The Build subtest confirms each snapshot compiles.
  • Integration test in internal/integration/omitimpls/ that exercises both the typed-impl path and the catch-all path end-to-end against the existing gqlgen test server.

I have:

@WillAbides
Copy link
Copy Markdown
Author

I tried this branch with the code that originally made me want this feature, and I found a few things to address:

  • omit_unreferenced_implementations should be settable with a directive
  • A catch_all_suffix config would be nice
  • Similar to above, a catch_all_name directive

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.

Interfaces with many implementations generate massive output even when only one type is queried via fragment

1 participant