44
55import typer
66import ujson
7- import yaml
87from pydantic import ValidationError
98from rich .console import Console
10- from ujson import JSONDecodeError
119
1210from ..async_typer import AsyncTyper
1311from ..ctl .client import initialize_client , initialize_client_sync
1412from ..ctl .exceptions import QueryNotFoundError
1513from ..ctl .utils import catch_exception , find_graphql_query , parse_cli_vars
1614from ..exceptions import GraphQLError
1715from ..utils import get_branch , write_to_file
16+ from ..yaml import SchemaFile
1817from .parameters import CONFIG_PARAM
18+ from .utils import load_yamlfile_from_disk_and_exit
1919
2020app = AsyncTyper ()
2121console = Console ()
@@ -33,16 +33,15 @@ def callback() -> None:
3333async def validate_schema (schema : Path , _ : str = CONFIG_PARAM ) -> None :
3434 """Validate the format of a schema file either in JSON or YAML"""
3535
36- try :
37- schema_data = yaml .safe_load (schema .read_text ()) or {}
38- except JSONDecodeError as exc :
39- console .print ("[red]Invalid JSON file" )
40- raise typer .Exit (1 ) from exc
36+ schema_data = load_yamlfile_from_disk_and_exit (paths = [schema ], file_type = SchemaFile , console = console )
37+ if not schema_data :
38+ console .print (f"[red]Unable to find { schema } " )
39+ raise typer .Exit (1 )
4140
4241 client = initialize_client ()
4342
4443 try :
45- client .schema .validate (schema_data )
44+ client .schema .validate (schema_data [ 0 ]. payload )
4645 except ValidationError as exc :
4746 console .print (f"[red]Schema not valid, found { len (exc .errors ())} error(s)" )
4847 for error in exc .errors ():
0 commit comments