-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Description:
Currently, ariadne-codegen
always includes the __typename
field in generated queries and models. This is usually correct and aligns with the GraphQL specification, since __typename
is a valid meta-field on all object types and helps with cache normalization and type resolution.
However, when integrating with some GraphQL APIs that are not fully spec-compliant, adding __typename
can cause errors. For example, some servers throw exceptions or reject queries when __typename
is included on nested objects.
In these cases, it would be very useful to have a configuration option to disable automatic insertion of __typename
(e.g., include_typename: false
in the config file).
Motivation:
- Improves compatibility with non-standard GraphQL implementations.
- Makes
ariadne-codegen
more flexible for real-world integration scenarios where the API cannot be changed. - Still allows the default behavior (with
__typename
enabled) for users who work with spec-compliant APIs.
Proposed solution:
- Add a configuration flag (e.g.,
include_typename: true|false
) to the codegen config. - Default should remain
true
to preserve current behavior and spec alignment. - If
false
, codegen should skip adding__typename
fields in queries and models.
Example:
# codegen.yml
schema_path: schema.graphql
queries_path: queries.graphql
target_package_path: generated
include_typename: false # <--- new option
This would allow users to generate queries without __typename
when required by specific APIs.