Skip to content

Commit

Permalink
Merge pull request #48 from USCbiostats/issue-47-class-generator-scri…
Browse files Browse the repository at this point in the history
…pt-error

For #47
  • Loading branch information
mugitty authored Oct 17, 2024
2 parents 4cb9354 + 612f816 commit 4386a87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Follow the https://github.com/USCbiostats/annoq-database repository and use the

### Dynamic Snps class generation

Annoq has 500+ attributes, so the strawberry type for it had to be generated dynamically as it would not make sense to manually write 500 fields. Since the class is already present in this repository there is no need to run the following code again, but just for knowledge:
Annoq has 500+ attributes, so the strawberry type for it had to be generated dynamically as it would not make sense to manually write 500 fields. This class has to be executed whenever where are any changes in the schema:

First a json schema was generated which takes the mapping for the elasticsearch database and creates a schema for a pydantic Baseclass.
After this scripts/class_generators/class_schema.json was generated. The python file of the pydantic Baseclass - models/Snps.py is generated using datamodel-codegen.
Expand Down
4 changes: 4 additions & 0 deletions scripts/class_generators/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ES_URL:str = os.getenv("ES_URL")
ES_INDEX:str = os.getenv("ES_INDEX")
GENERATED_SCHEMA_DIR = './scripts/class_generators/generated_schemas'
GENERATED_MODEL_DIR = './src/graphql/models/generated/'
TYPE_MAPPINGS = {
"long": {"type": "integer", "format": "int64"},
"integer": {"type": "integer", "format": "int32"},
Expand Down Expand Up @@ -106,6 +107,9 @@ def write_to_json(data, output_file, indent=None):

if not os.path.exists(GENERATED_SCHEMA_DIR):
os.makedirs(GENERATED_SCHEMA_DIR)

if not os.path.exists(GENERATED_MODEL_DIR):
os.makedirs(GENERATED_MODEL_DIR)

loop = asyncio.get_event_loop()
mapping = loop.run_until_complete(get_mapping())
Expand Down

0 comments on commit 4386a87

Please sign in to comment.