Fix __typename field handling to use GraphQLString #388
+49
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix __typename field handling to use GraphQLString instead of creating new scalar
Description
Fixes a bug where code generation fails with
TypeError: Redefinition of reserved type 'String'when processing queries that include__typenamefields. The issue occurs because__typenameis a GraphQL meta-field that isn't explicitly defined in schema type maps, so the code falls back to creating a field definition. The original implementation incorrectly attempted to create a newGraphQLScalarType(name="String"), which fails because "String" is a reserved built-in type.Minimal Example
Schema:
Query:
Before (fails):
After (works):
Changes
GraphQLStringimport toariadne_codegen/client_generators/result_types.py_get_field_from_schema()to useGraphQLStringinstead of creating a new scalar for__typenamehandlingtest_get_field_from_schema_handles_typename_correctly()to validate the fixTesting
test_include_typename.py)__typenamefield handling and would fail without the fixType of Change
Checklist