Skip to content

Commit

Permalink
feat: add model generator
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Sep 27, 2024
1 parent ea9103b commit 322cb49
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 58 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repos:
- id: check-toml
- id: check-yaml
- id: check-json
- id: check-docstring-first
- id: check-merge-conflict
- id: check-added-large-files # check for file bigger than 500kb
- id: debug-statements
Expand Down
16 changes: 16 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ tasks:
- black .
- mypy .

gen-gql:
desc: generate grpc python files
generates:
- ./api/**/*.py
sources:
- ./proto/**/*.proto
- poetry.lock
cmds:
- >-
datamodel-codegen
--input gql/schema.graphql
--input-file-type graphql
--output gql/model.py
--output-model-type dataclasses.dataclass
# --use-standard-collections

gen-grpc:
desc: generate grpc python files
generates:
Expand Down
37 changes: 30 additions & 7 deletions gql/model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
from typing import TypedDict
# generated by datamodel-codegen:
# filename: schema.graphql
# timestamp: 2024-09-27T16:44:53+00:00

from __future__ import annotations

class CollectTimeline(TypedDict):
id: int
action: int
user_id: int
subject_id: list[int]
created_at: int
from dataclasses import dataclass
from typing import List, TypeAlias

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

Int: TypeAlias = int
"""
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
"""

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.
"""


@dataclass
class CollectTimeline:
action: Int
created_at: Int
id: Int
subject_id: List[Int]
user_id: Int
Loading

0 comments on commit 322cb49

Please sign in to comment.