diff --git a/README.md b/README.md index 2103ed9..55f1e35 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/scripts/class_generators/generator.py b/scripts/class_generators/generator.py index f7a9896..a08fdd0 100644 --- a/scripts/class_generators/generator.py +++ b/scripts/class_generators/generator.py @@ -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"}, @@ -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())