Skip to content

Commit

Permalink
Close #1719 (#1730)
Browse files Browse the repository at this point in the history
* Update Scalar.jinja2

* Update Scalar.jinja2 2

* Add test

generation datamodel from github graphql api https://docs.github.com/en/graphql/overview/public-schema

* Fix test test_main_graphql_github_api

* Remove test test_main_graphql_github_api
  • Loading branch information
denisart authored Nov 22, 2023
1 parent cd1e97a commit ef1f97e
Show file tree
Hide file tree
Showing 14 changed files with 84,452 additions and 30 deletions.
8 changes: 5 additions & 3 deletions datamodel_code_generator/model/template/Scalar.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{ class_name }}: TypeAlias = {{ py_type }}
{%- if description %}
# {{ description }}
{%- endif %}
{{ class_name }}: TypeAlias = {{ py_type }}
"""
{{ description }}
"""
{%- endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@

from mymodule.myclass import MyCustomPythonClass

# The `Boolean` scalar type represents `true` or `false`.
Boolean: TypeAlias = bool
"""
The `Boolean` scalar type represents `true` or `false`.
"""


Date: TypeAlias = date


# DateTime (ISO8601, example: 2020-01-01T10:11:12+00:00)
DateTime: TypeAlias = datetime
"""
DateTime (ISO8601, example: 2020-01-01T10:11:12+00:00)
"""


MyCustomClass: TypeAlias = MyCustomPythonClass


# 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.
String: TypeAlias = str
"""
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.
"""


class A(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@
from pydantic import BaseModel, Field
from typing_extensions import Literal

# The `Boolean` scalar type represents `true` or `false`.
Boolean: TypeAlias = bool
"""
The `Boolean` scalar type represents `true` or `false`.
"""


Date: TypeAlias = date


# DateTime (ISO8601, example: 2020-01-01T10:11:12+00:00)
DateTime: TypeAlias = datetime
"""
DateTime (ISO8601, example: 2020-01-01T10:11:12+00:00)
"""


MyCustomClass: TypeAlias = MyCustomPythonClass


# 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.
String: TypeAlias = str
"""
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.
"""


class A(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@
from pydantic import BaseModel, Field
from typing_extensions import Literal

# The `Boolean` scalar type represents `true` or `false`.
Boolean: TypeAlias = bool
"""
The `Boolean` scalar type represents `true` or `false`.
"""


# The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
ID: TypeAlias = str
"""
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
"""


Long: TypeAlias = int


# 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.
String: TypeAlias = str
"""
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.
"""


class A(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
from pydantic import BaseModel, Field
from typing_extensions import Literal

# The `Boolean` scalar type represents `true` or `false`.
Boolean: TypeAlias = bool
"""
The `Boolean` scalar type represents `true` or `false`.
"""


# 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.
String: TypeAlias = str
"""
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.
"""


class A(BaseModel):
Expand Down
8 changes: 6 additions & 2 deletions tests/data/expected/main/main_graphql_enums/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
from enum import Enum
from typing import TypeAlias

# The `Boolean` scalar type represents `true` or `false`.
Boolean: TypeAlias = bool
"""
The `Boolean` scalar type represents `true` or `false`.
"""


# 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.
String: TypeAlias = str
"""
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.
"""


class Color(Enum):
Expand Down
8 changes: 6 additions & 2 deletions tests/data/expected/main/main_graphql_field_aliases/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
from pydantic import BaseModel, Field
from typing_extensions import Literal

# The `Boolean` scalar type represents `true` or `false`.
Boolean: TypeAlias = bool
"""
The `Boolean` scalar type represents `true` or `false`.
"""


DateTime: TypeAlias = str


# 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.
String: TypeAlias = str
"""
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.
"""


class DateTimePeriod(BaseModel):
Expand Down
Loading

0 comments on commit ef1f97e

Please sign in to comment.