Skip to content

Add include_typename configuration option for better GraphQL API compatibility#379

Merged
DamianCzajkowski merged 13 commits intomirumee:mainfrom
jacksonpradolima:main
Oct 20, 2025
Merged

Add include_typename configuration option for better GraphQL API compatibility#379
DamianCzajkowski merged 13 commits intomirumee:mainfrom
jacksonpradolima:main

Conversation

@jacksonpradolima
Copy link
Contributor

@jacksonpradolima jacksonpradolima commented Sep 9, 2025

closes #374

This pull request introduces a new include_typename option throughout the code generation pipeline, allowing users to control whether __typename fields and union discriminators are included in generated client code. The change is propagated through settings, generators, and helper functions, and the logic for handling unions and fragments is updated to respect this new flag.

Settings and Configuration

  • Added include_typename boolean option to the ClientSettings dataclass in settings.py, including messaging to indicate whether __typename fields are included in generated queries. [1] [2] [3]

Generator Initialization and Propagation

  • Updated constructors for key generators (FragmentsGenerator, PackageGenerator, ResultTypesGenerator) to accept and store the include_typename flag, and ensured it is passed through all relevant generator creation and function calls. [1] [2] [3] [4] [5] [6] [7] [8]

Union Annotation and Typename Logic

  • Modified the union annotation logic in result_fields.py so that when include_typename=False, union types are generated without the discriminator (i.e., without __typename in Annotated). [1] [2] [3] [4]

Field and Fragment Handling

  • Updated fragment and field parsing logic to accept and respect the include_typename flag, ensuring that __typename fields are only added when requested. [1] [2] [3] [4]

Pipeline Integration

  • Ensured the include_typename setting is propagated through the package generator pipeline and all relevant function calls, so the behavior is consistent for all generated code.

These changes give users fine-grained control over the inclusion of __typename fields and union discriminators in generated clients, improving flexibility and compatibility with various GraphQL server configurations.

Copilot AI and others added 8 commits September 9, 2025 15:19
…tTypesGenerator

Co-authored-by: jacksonpradolima <7774063+jacksonpradolima@users.noreply.github.com>
Co-authored-by: jacksonpradolima <7774063+jacksonpradolima@users.noreply.github.com>
Co-authored-by: jacksonpradolima <7774063+jacksonpradolima@users.noreply.github.com>
- Fix parsing error in test: change 'animals' to 'animal' to match schema
- Always generate discriminator for union types (even when include_typename=False)
- Make typename__ field Optional[Literal[...]] = None when include_typename=False
- This allows models to work with APIs that don't return __typename while maintaining union discrimination capability

Co-authored-by: jacksonpradolima <7774063+jacksonpradolima@users.noreply.github.com>
…name unavailable

Co-authored-by: jacksonpradolima <7774063+jacksonpradolima@users.noreply.github.com>
Co-authored-by: jacksonpradolima <7774063+jacksonpradolima@users.noreply.github.com>
…-374

Add `include_typename` configuration option for better GraphQL API compatibility
@jacksonpradolima
Copy link
Contributor Author

Hey @DamianCzajkowski @KarolJagodzinski can you take a look?

@DamianCzajkowski
Copy link
Collaborator

Hi @jacksonpradolima your code looks really nice, are you able to fix those issues with linters?

Copilot AI and others added 3 commits October 4, 2025 17:05
Co-authored-by: jacksonpradolima <7774063+jacksonpradolima@users.noreply.github.com>
…-43f1-b578-d34db1b5530c

Fix linting errors: line length and import sorting
@jacksonpradolima
Copy link
Contributor Author

@DamianCzajkowski thanks!
linters fixed

@DamianCzajkowski
Copy link
Collaborator

It looks like it's still failing. Try to run:

hatch fmt --check
hatch run types:check

and then tests:
hatch test

@jacksonpradolima
Copy link
Contributor Author

@DamianCzajkowski
Sorry about that, I tried to parallelize my tasks, my bad.
Ok, manually fixed and tested locally. Working fine. Can you try again?

@DamianCzajkowski DamianCzajkowski merged commit a13d74d into mirumee:main Oct 20, 2025
5 checks passed
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.

Add option to disable __typename in generated queries

3 participants