graphdoc.data.parser module
- class graphdoc.data.parser.Parser(type_mapping: dict[type, str] | None = None)[source]
Bases:
object
A class for parsing and handling of GraphQL objects.
- DEFAULT_NODE_TYPES = {<class 'graphql.language.ast.DocumentNode'>: 'full schema', <class 'graphql.language.ast.EnumTypeDefinitionNode'>: 'enum schema', <class 'graphql.language.ast.EnumValueDefinitionNode'>: 'enum value', <class 'graphql.language.ast.ObjectTypeDefinitionNode'>: 'table schema'}
- static _check_node_type(node: Node, type_mapping: dict[type, str] | None = None) str [source]
Check the type of a schema node.
- static parse_schema_from_file(schema_file: str | Path, schema_directory_path: str | Path | None = None) DocumentNode [source]
Parse a schema from a file.
- static update_node_descriptions(node: Node, new_value: str | None = None) Node [source]
Given a GraphQL node, recursively traverse the node and its children, updating all descriptions with the new value. Can also be used to remove descriptions by passing None as the new value.
- Parameters:
node (Node) – The GraphQL node to update
new_value (Optional[str]) – The new description value. If None, the description will be removed.
- Returns:
The updated node
- Return type:
Node
- static count_description_pattern_matching(node: Node, pattern: str) dict[str, int] [source]
Counts the number of times a pattern matches a description in a node and its children.
- static fill_empty_descriptions(node: Node, new_column_value: str = 'Description for column: {}', new_table_value: str = 'Description for table: {}', use_value_name: bool = True, value_name: str | None = None)[source]
Recursively traverse the node and its children, filling in empty descriptions with the new column or table value. Do not update descriptions that already have a value. Default values are provided for the new column and table descriptions.
- Parameters:
- Returns:
The updated node
- Return type:
Node
- static schema_equality_check(gold_node: Node, check_node: Node) bool [source]
A method to check if two schema nodes are equal. Only checks that the schemas structures are equal, not the descriptions.
- Parameters:
gold_node (Node) – The gold standard schema node
check_node (Node) – The schema node to check
- Returns:
Whether the schemas are equal
- Return type:
- static schema_object_from_file(schema_file: str | Path, category: str | None = None, rating: int | None = None) SchemaObject [source]
Parse a schema object from a file.