def sdl( file: str, output: str = typer.Option(None, help="save output into a file."), ) -> None: """Generate SDL aka GraphQL schema from ADFH file. Args: file: Path to ADFH file. output: If --output is used, it will save it in file. """ console = Console() data = read_adfh_file(file=file) if type(data) == str: console.print(data, style="bold red") else: ihsan_type = IhsanType(**data) # type: ignore sdl_output = to_sdl(schema=ihsan_type) if output: typer.confirm( f"The output will be saved in {output}, are you sure?", abort=True) with open(output, "w") as output_file: output_file.write(sdl_output) else: console.print(sdl_output, style="bold green") console.print( "Use -> https://app.graphqleditor.com/ to test the schema :)", style="bold blue", )
def test_to_sdl_successfully(tmp_path: pathlib.PosixPath, toml_adfh: str) -> None: """It exits with a status code of zero.""" create_adfh_file(directory_path=tmp_path, adfh=toml_adfh) data = read_adfh_file(file=(pathlib.Path(tmp_path) / "adfh.toml").as_posix()) ihsan_type = IhsanType(**data) sdl_output = to_sdl(schema=ihsan_type) assert "enum StatusType" in sdl_output assert "REJECTED" in sdl_output assert "APPROVED" in sdl_output assert "DENY" in sdl_output assert "type Item" in sdl_output assert "type Company" in sdl_output assert "title: String!" in sdl_output assert "id: String" in sdl_output assert "status: StatusType" in sdl_output assert "is_done: Boolean" in sdl_output assert "view: Int" in sdl_output assert "type Query" in sdl_output assert "todoList: [Item]" in sdl_output assert "CompanyList: [Company]" in sdl_output assert "todoDetail(id: String, ): Item" in sdl_output assert "type Mutation" in sdl_output assert "todoAdd(title: String!, ): Item" in sdl_output assert "companyRemove(id: String, ): Company" in sdl_output assert "schema" in sdl_output assert "query: Query" in sdl_output assert "mutation: Mutation" in sdl_output
def test_to_sdl_without_choice_successfully( tmp_path: pathlib.PosixPath, toml_adfh_without_choice: str) -> None: """It exits with a status code of zero.""" create_adfh_file(directory_path=tmp_path, adfh=toml_adfh_without_choice) data = read_adfh_file(file=(pathlib.Path(tmp_path) / "adfh.toml").as_posix()) ihsan_type = IhsanType(**data) sdl_output = to_sdl(schema=ihsan_type) assert "type Item" in sdl_output assert "type Company" in sdl_output assert "title: String!" in sdl_output assert "id: String" in sdl_output assert "is_done: Boolean" in sdl_output assert "view: Int" in sdl_output assert "schema" in sdl_output assert "query: Query" in sdl_output assert "mutation: Mutation" in sdl_output
def test_to_sdl_without_actions_successfully(tmp_path: pathlib.PosixPath, toml_adfh: str) -> None: """It exits with a status code of zero.""" create_adfh_file(directory_path=tmp_path, adfh=toml_adfh) data = read_adfh_file(file=(pathlib.Path(tmp_path) / "adfh.toml").as_posix()) data["adfh"].pop("actions") ihsan_type = IhsanType(**data) sdl_output = to_sdl(schema=ihsan_type) assert "enum StatusType" in sdl_output assert "REJECTED" in sdl_output assert "APPROVED" in sdl_output assert "DENY" in sdl_output assert "type Item" in sdl_output assert "type Company" in sdl_output assert "title: String!" in sdl_output assert "id: String" in sdl_output assert "status: StatusType" in sdl_output assert "is_done: Boolean" in sdl_output assert "view: Int" in sdl_output assert "schema" in sdl_output assert "query: Query" in sdl_output assert "mutation: Mutation" in sdl_output