File tree Expand file tree Collapse file tree
src/datamodel_code_generator/parser Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -482,7 +482,8 @@ def parse_field(
482482 data_type .reference = self .references [obj .name ]
483483
484484 obj = graphql .assert_named_type (obj )
485- data_type .type = obj .name
485+ if data_type .reference is None :
486+ data_type .type = obj .name
486487
487488 required = (not self .force_optional_for_required_fields ) and (not final_data_type .is_optional )
488489
Original file line number Diff line number Diff line change 1+ # generated by datamodel-codegen:
2+ # filename: enum-casing.graphql
3+ # timestamp: 2019-07-26T00:00:00+00:00
4+
5+ from __future__ import annotations
6+
7+ from enum import Enum
8+ from typing import Literal , Optional
9+
10+ from pydantic import BaseModel , Field
11+ from typing_extensions import TypeAlias
12+
13+ Boolean : TypeAlias = bool
14+ """
15+ The `Boolean` scalar type represents `true` or `false`.
16+ """
17+
18+
19+ String : TypeAlias = str
20+ """
21+ The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
22+ """
23+
24+
25+ class Lowercase (Enum ):
26+ foo = 'foo'
27+
28+
29+ class EnumRef (BaseModel ):
30+ bar : Lowercase
31+ typename__ : Optional [Literal ['EnumRef' ]] = Field ('EnumRef' , alias = '__typename' )
Original file line number Diff line number Diff line change 1+ enum lowercase {
2+ foo
3+ }
4+
5+ type EnumRef {
6+ bar : lowercase !
7+ }
Original file line number Diff line number Diff line change @@ -102,6 +102,21 @@ def test_main_graphql_field_aliases(output_file: Path) -> None:
102102 )
103103
104104
105+ @pytest .mark .skipif (
106+ black .__version__ .split ("." )[0 ] == "19" ,
107+ reason = "Installed black doesn't support the old style" ,
108+ )
109+ def test_main_graphql_enum_casing (output_file : Path ) -> None :
110+ """Test GraphQL code generation with enums."""
111+ run_main_and_assert (
112+ input_path = GRAPHQL_DATA_PATH / "enum-casing.graphql" ,
113+ output_path = output_file ,
114+ input_file_type = "graphql" ,
115+ assert_func = assert_file_content ,
116+ expected_file = "enum_casing.py" ,
117+ )
118+
119+
105120@pytest .mark .skipif (
106121 black .__version__ .split ("." )[0 ] == "19" ,
107122 reason = "Installed black doesn't support the old style" ,
You can’t perform that action at this time.
0 commit comments