1from typing import Any, List, Optional, Union 2 3from lark import v_args 4from lark.visitors import Transformer_InPlace 5 6from tartiflette.language.parsers.lark.transformers.converters import ( 7 lark_to_argument_node, 8 lark_to_boolean_value_node, 9 lark_to_description_node, 10 lark_to_directive_definition_node, 11 lark_to_directive_node, 12 lark_to_document_node, 13 lark_to_enum_type_definition_node, 14 lark_to_enum_type_extension_node, 15 lark_to_enum_value_definition_node, 16 lark_to_enum_value_node, 17 lark_to_field_definition_node, 18 lark_to_float_value_node, 19 lark_to_implements_interfaces_node, 20 lark_to_input_object_type_definition_node, 21 lark_to_input_object_type_extension_node, 22 lark_to_input_value_definition_node, 23 lark_to_int_value_node, 24 lark_to_interface_type_definition_node, 25 lark_to_interface_type_extension_node, 26 lark_to_list_type_node, 27 lark_to_list_value_node, 28 lark_to_name_node, 29 lark_to_named_type_node, 30 lark_to_non_null_type_node, 31 lark_to_null_value_node, 32 lark_to_object_field_node, 33 lark_to_object_type_definition_node, 34 lark_to_object_type_extension_node, 35 lark_to_object_value_node, 36 lark_to_operation_type_definition_node, 37 lark_to_scalar_type_definition_node, 38 lark_to_scalar_type_extension_node, 39 lark_to_schema_definition_node, 40 lark_to_schema_extension_node, 41 lark_to_string_value_node, 42 lark_to_union_type_definition_node, 43 lark_to_union_type_extension_node, 44) 45 46__all__ = ("NodeTransformer",) 47 48 49class SchemaNode: 50 """ 51 A class which fit the lark.Token API to be able to use instances from these 52 classes the same way. 53 """ 54 55 __slots__ = ("type", "value") 56 57 def __init__( 58 self, 59 type: str, # pylint: disable=redefined-builtin 60 value: Union["Node", List["Node"]], 61 ) -> None: 62 """ 63 :param type: type of the schema node 64 :param value: value of the schema node 65 :type type: str 66 :type value: Union[Node, List[Node]] 67 """ 68 self.type = type 69 self.value = value 70 71 def __eq__(self, other: Any) -> bool: 72 """ 73 Returns True if `other` instance is identical to `self`. 74 :param other: object instance to compare to `self` 75 :type other: Any 76 :return: whether or not `other` is identical to `self` 77 :rtype: bool 78 """ 79 return self is other or ( 80 isinstance(other, SchemaNode) 81 and (self.type == other.type and self.value == other.value) 82 ) 83 84 def __repr__(self) -> str: 85 """ 86 Returns the representation of an SchemaNode instance. 87 :return: the representation of an SchemaNode instance 88 :rtype: str 89 """ 90 return "SchemaNode(type=%r, value=%r)" % (self.type, self.value) 91 92 93@v_args(tree=True) 94class NodeTransformer(Transformer_InPlace): 95 """ 96 Parses a Tree previously cleaned with TokenTransformer and builds a 97 DocumentNode instance. 98 """ 99 100 # pylint: disable=too-many-public-methods 101 # pylint: disable=no-self-use 102 103 def __init__(self) -> None: 104 super().__init__() 105 self.document_node: Optional["DocumentNode"] = None 106 107 def int_value(self, tree: "Tree") -> "SchemaNode": 108 """ 109 Creates and returns a SchemaNode instance of type "int_value" with a 110 IntValueNode instance as value (extracted from the parsing of the tree 111 instance). 112 :param tree: the Tree to parse in order to extract the proper node 113 :type tree: Tree 114 :return: a SchemaNode instance of type "int_value" with an IntValueNode 115 instance as value 116 :rtype: SchemaNode 117 """ 118 return SchemaNode(type="int_value", value=lark_to_int_value_node(tree)) 119 120 def float_value(self, tree: "Tree") -> "SchemaNode": 121 """ 122 Creates and returns a SchemaNode instance of type "float_value" with a 123 FloatValueNode instance as value (extracted from the parsing of the 124 tree instance). 125 :param tree: the Tree to parse in order to extract the proper node 126 :type tree: Tree 127 :return: a SchemaNode instance of type "float_value" with a 128 FloatValueNode instance as value 129 :rtype: SchemaNode 130 """ 131 # pylint: disable=no-self-use 132 return SchemaNode( 133 type="float_value", value=lark_to_float_value_node(tree) 134 ) 135 136 def string_value(self, tree: "Tree") -> "SchemaNode": 137 """ 138 Creates and returns a SchemaNode instance of type "string_value" with a 139 StringValueNode instance as value (extracted from the parsing of the 140 tree instance). 141 :param tree: the Tree to parse in order to extract the proper node 142 :type tree: Tree 143 :return: a SchemaNode instance of type "string_value" with a 144 StringValueNode instance as value 145 :rtype: SchemaNode 146 """ 147 # pylint: disable=no-self-use 148 return SchemaNode( 149 type="string_value", value=lark_to_string_value_node(tree) 150 ) 151 152 def boolean_value(self, tree: "Tree") -> "SchemaNode": 153 """ 154 Creates and returns a SchemaNode instance of type "boolean_value" with 155 a BooleanValueNode instance as value (extracted from the parsing of the 156 tree instance). 157 :param tree: the Tree to parse in order to extract the proper node 158 :type tree: Tree 159 :return: a SchemaNode instance of type "boolean_value" with a 160 BooleanValueNode instance as value 161 :rtype: SchemaNode 162 """ 163 # pylint: disable=no-self-use 164 return SchemaNode( 165 type="boolean_value", value=lark_to_boolean_value_node(tree) 166 ) 167 168 def null_value(self, tree: "Tree") -> "SchemaNode": 169 """ 170 Creates and returns a SchemaNode instance of type "null_value" with a 171 NullValueNode instance as value (extracted from the parsing of the tree 172 instance). 173 :param tree: the Tree to parse in order to extract the proper node 174 :type tree: Tree 175 :return: a SchemaNode instance of type "null_value" with a 176 NullValueNode instance as value 177 :rtype: SchemaNode 178 """ 179 # pylint: disable=no-self-use 180 return SchemaNode( 181 type="null_value", value=lark_to_null_value_node(tree) 182 ) 183 184 def enum_value(self, tree: "Tree") -> "SchemaNode": 185 """ 186 Creates and returns a SchemaNode instance of type "enum_value" with an 187 EnumValueNode instance as value (extracted from the parsing of the tree 188 instance). 189 :param tree: the Tree to parse in order to extract the proper node 190 :type tree: Tree 191 :return: a SchemaNode instance of type "enum_value" with an 192 EnumValueNode instance as value 193 :rtype: SchemaNode 194 """ 195 # pylint: disable=no-self-use 196 return SchemaNode( 197 type="enum_value", value=lark_to_enum_value_node(tree) 198 ) 199 200 def list_value(self, tree: "Tree") -> "SchemaNode": 201 """ 202 Creates and returns a SchemaNode instance of type "list_value" with a 203 ListValueNode instance as value (extracted from the parsing of the tree 204 instance). 205 :param tree: the Tree to parse in order to extract the proper node 206 :type tree: Tree 207 :return: a SchemaNode instance of type "list_value" with a 208 ListValueNode instance as value 209 :rtype: SchemaNode 210 """ 211 # pylint: disable=no-self-use 212 return SchemaNode( 213 type="list_value", value=lark_to_list_value_node(tree) 214 ) 215 216 def object_field(self, tree: "Tree") -> "SchemaNode": 217 """ 218 Creates and returns a SchemaNode instance of type "object_field" with 219 an ObjectFieldNode instance as value (extracted from the parsing of the 220 tree instance). 221 :param tree: the Tree to parse in order to extract the proper node 222 :type tree: Tree 223 :return: a SchemaNode instance of type "object_field" with an 224 ObjectFieldNode instance as value 225 :rtype: SchemaNode 226 """ 227 # pylint: disable=no-self-use 228 return SchemaNode( 229 type="object_field", value=lark_to_object_field_node(tree) 230 ) 231 232 def object_value(self, tree: "Tree") -> "SchemaNode": 233 """ 234 Creates and returns a SchemaNode instance of type "object_value" with 235 an ObjectValueNode instance as value (extracted from the parsing of the 236 tree instance). 237 :param tree: the Tree to parse in order to extract the proper node 238 :type tree: Tree 239 :return: a SchemaNode instance of type "object_value" with an 240 ObjectValueNode instance as value 241 :rtype: SchemaNode 242 """ 243 # pylint: disable=no-self-use 244 return SchemaNode( 245 type="object_value", value=lark_to_object_value_node(tree) 246 ) 247 248 def value(self, tree: "Tree") -> "SchemaNode": 249 """ 250 Creates and returns a SchemaNode instance of type "value" with a 251 ValueNode instance as value (extracted from the parsing of the tree 252 instance). 253 :param tree: the Tree to parse in order to extract the proper node 254 :type tree: Tree 255 :return: a SchemaNode instance of type "value" with a ValueNode 256 instance as value 257 :rtype: SchemaNode 258 """ 259 # pylint: disable=no-self-use 260 return SchemaNode(type="value", value=tree.children[0].value) 261 262 def name(self, tree: "Tree") -> "SchemaNode": 263 """ 264 Creates and returns a SchemaNode instance of type "name" with a 265 NameNode instance as value (extracted from the parsing of the tree 266 instance). 267 :param tree: the Tree to parse in order to extract the proper node 268 :type tree: Tree 269 :return: a SchemaNode instance of type "name" with a NameNode instance 270 as value 271 :rtype: SchemaNode 272 """ 273 # pylint: disable=no-self-use 274 return SchemaNode(type="name", value=lark_to_name_node(tree)) 275 276 def description(self, tree: "Tree") -> "SchemaNode": 277 """ 278 Creates and returns a SchemaNode instance of type "description" with a 279 DescriptionNode instance as value (extracted from the parsing of the 280 tree instance). 281 :param tree: the Tree to parse in order to extract the proper node 282 :type tree: Tree 283 :return: a SchemaNode instance of type "description" with a 284 DescriptionNode instance as value 285 :rtype: SchemaNode 286 """ 287 # pylint: disable=no-self-use 288 return SchemaNode( 289 type="description", value=lark_to_description_node(tree) 290 ) 291 292 def named_type(self, tree: "Tree") -> "SchemaNode": 293 """ 294 Creates and returns a SchemaNode instance of type "named_type" with a 295 NamedTypeNode instance as value (extracted from the parsing of the tree 296 instance). 297 :param tree: the Tree to parse in order to extract the proper node 298 :type tree: Tree 299 :return: a SchemaNode instance of type "named_type" with a 300 NamedTypeNode instance as value 301 :rtype: SchemaNode 302 """ 303 # pylint: disable=no-self-use 304 return SchemaNode( 305 type="named_type", value=lark_to_named_type_node(tree) 306 ) 307 308 def argument(self, tree: "Tree") -> "SchemaNode": 309 """ 310 Creates and returns a SchemaNode instance of type "argument" with a 311 ArgumentNode instance as value (extracted from the parsing of the tree 312 instance). 313 :param tree: the Tree to parse in order to extract the proper node 314 :type tree: Tree 315 :return: a SchemaNode instance of type "argument" with an ArgumentNode 316 instance as value 317 :rtype: SchemaNode 318 """ 319 # pylint: disable=no-self-use 320 return SchemaNode(type="argument", value=lark_to_argument_node(tree)) 321 322 def arguments(self, tree: "Tree") -> "SchemaNode": 323 """ 324 Creates and returns a SchemaNode instance of type "arguments" with a 325 list of ArgumentNode instance as value (extracted from the parsing of 326 the tree instance). 327 :param tree: the Tree to parse in order to extract the proper node 328 :type tree: Tree 329 :return: a SchemaNode instance of type "arguments" with a list of 330 ArgumentNode instance as value 331 :rtype: SchemaNode 332 """ 333 # pylint: disable=no-self-use 334 return SchemaNode( 335 type="arguments", value=[token.value for token in tree.children] 336 ) 337 338 def directive(self, tree: "Tree") -> "SchemaNode": 339 """ 340 Creates and returns a SchemaNode instance of type "directive" with a 341 DirectiveNode instance as value (extracted from the parsing of the tree 342 instance). 343 :param tree: the Tree to parse in order to extract the proper node 344 :type tree: Tree 345 :return: a SchemaNode instance of type "directive" with a DirectiveNode 346 instance as value 347 :rtype: SchemaNode 348 """ 349 # pylint: disable=no-self-use 350 return SchemaNode(type="directive", value=lark_to_directive_node(tree)) 351 352 def directives(self, tree: "Tree") -> "SchemaNode": 353 """ 354 Creates and returns a SchemaNode instance of type "directives" with a 355 list of DirectiveNode instance as value (extracted from the parsing of 356 the tree instance). 357 :param tree: the Tree to parse in order to extract the proper node 358 :type tree: Tree 359 :return: a SchemaNode instance of type "directives" with a list of 360 DirectiveNode instance as value 361 :rtype: SchemaNode 362 """ 363 # pylint: disable=no-self-use 364 return SchemaNode( 365 type="directives", value=[child.value for child in tree.children] 366 ) 367 368 def operation_type(self, tree: "Tree") -> "SchemaNode": 369 """ 370 Creates and returns a SchemaNode instance of type "operation_type" with 371 a string as value (extracted from the parsing of the tree instance). 372 :param tree: the Tree to parse in order to extract the proper node 373 :type tree: Tree 374 :return: a SchemaNode instance of type "operation_type" with a string 375 as value 376 :rtype: SchemaNode 377 """ 378 # pylint: disable=no-self-use 379 return SchemaNode(type="operation_type", value=tree.children[0].value) 380 381 def operation_type_definition(self, tree: "Tree") -> "SchemaNode": 382 """ 383 Creates and returns a SchemaNode instance of type 384 "operation_type_definition" with an OperationTypeDefinitionNode 385 instance as value (extracted from the parsing of the tree instance). 386 :param tree: the Tree to parse in order to extract the proper node 387 :type tree: Tree 388 :return: a SchemaNode instance of type "operation_type_definition" with 389 an OperationTypeDefinitionNode instance as value 390 :rtype: SchemaNode 391 """ 392 # pylint: disable=no-self-use 393 return SchemaNode( 394 type="operation_type_definition", 395 value=lark_to_operation_type_definition_node(tree), 396 ) 397 398 def schema_definition(self, tree: "Tree") -> "SchemaNode": 399 """ 400 Creates and returns a SchemaNode instance of type "schema_definition" 401 with a SchemaDefinitionNode instance as value (extracted from the 402 parsing of the tree instance). 403 :param tree: the Tree to parse in order to extract the proper node 404 :type tree: Tree 405 :return: a SchemaNode instance of type "schema_definition" with a 406 SchemaDefinitionNode instance as value 407 :rtype: SchemaNode 408 """ 409 # pylint: disable=no-self-use 410 return SchemaNode( 411 type="schema_definition", 412 value=lark_to_schema_definition_node(tree), 413 ) 414 415 def scalar_type_definition(self, tree: "Tree") -> "SchemaNode": 416 """ 417 Creates and returns a SchemaNode instance of type 418 "scalar_type_definition" with a ScalarTypeDefinitionNode instance as 419 value (extracted from the parsing of the tree instance). 420 :param tree: the Tree to parse in order to extract the proper node 421 :type tree: Tree 422 :return: a SchemaNode instance of type "scalar_type_definition" with a 423 ScalarTypeDefinitionNode instance as value 424 :rtype: SchemaNode 425 """ 426 # pylint: disable=no-self-use 427 return SchemaNode( 428 type="scalar_type_definition", 429 value=lark_to_scalar_type_definition_node(tree), 430 ) 431 432 def list_type(self, tree: "Tree") -> "SchemaNode": 433 """ 434 Creates and returns a SchemaNode instance of type "list_type" with a 435 ListTypeNode instance as value (extracted from the parsing of the tree 436 instance). 437 :param tree: the Tree to parse in order to extract the proper node 438 :type tree: Tree 439 :return: a SchemaNode instance of type "list_type" with a ListTypeNode 440 instance as value 441 :rtype: SchemaNode 442 """ 443 # pylint: disable=no-self-use 444 return SchemaNode(type="list_type", value=lark_to_list_type_node(tree)) 445 446 def non_null_type(self, tree: "Tree") -> "SchemaNode": 447 """ 448 Creates and returns a SchemaNode instance of type "non_null_type" with 449 a NonNullTypeNode instance as value (extracted from the parsing of the 450 tree instance). 451 :param tree: the Tree to parse in order to extract the proper node 452 :type tree: Tree 453 :return: a SchemaNode instance of type "non_null_type" with a 454 NonNullTypeNode instance as value 455 :rtype: SchemaNode 456 """ 457 # pylint: disable=no-self-use 458 return SchemaNode( 459 type="non_null_type", value=lark_to_non_null_type_node(tree) 460 ) 461 462 def type(self, tree: "Tree") -> "SchemaNode": 463 """ 464 Creates and returns a SchemaNode instance of type "type" with a 465 TypeNode instance as value (extracted from the parsing of the tree 466 instance). 467 :param tree: the Tree to parse in order to extract the proper node 468 :type tree: Tree 469 :return: a SchemaNode instance of type "type" with a TypeNode instance 470 as value 471 :rtype: SchemaNode 472 """ 473 # pylint: disable=no-self-use 474 return SchemaNode(type="type", value=tree.children[0].value) 475 476 def default_value(self, tree: "Tree") -> "SchemaNode": 477 """ 478 Creates and returns a SchemaNode instance of type "default_value" with 479 a ValueNode instance as value (extracted from the parsing of the tree 480 instance). 481 :param tree: the Tree to parse in order to extract the proper node 482 :type tree: Tree 483 :return: a SchemaNode instance of type "default_value" with a ValueNode 484 instance as value 485 :rtype: SchemaNode 486 """ 487 # pylint: disable=no-self-use 488 return SchemaNode(type="default_value", value=tree.children[0].value) 489 490 def input_value_definition(self, tree: "Tree") -> "SchemaNode": 491 """ 492 Creates and returns a SchemaNode instance of type 493 "input_value_definition" with an InputValueDefinitionNode instance 494 as value (extracted from the parsing of the tree instance). 495 :param tree: the Tree to parse in order to extract the proper node 496 :type tree: Tree 497 :return: a SchemaNode instance of type "input_value_definition" with an 498 InputValueDefinitionNode instance as value 499 :rtype: SchemaNode 500 """ 501 # pylint: disable=no-self-use 502 return SchemaNode( 503 type="input_value_definition", 504 value=lark_to_input_value_definition_node(tree), 505 ) 506 507 def arguments_definition(self, tree: "Tree") -> "SchemaNode": 508 """ 509 Creates and returns a SchemaNode instance of type 510 "arguments_definition" with a list of InputValueDefinitionNode instance 511 as value (extracted from the parsing of the tree instance). 512 :param tree: the Tree to parse in order to extract the proper node 513 :type tree: Tree 514 :return: a SchemaNode instance of type "arguments_definition" with a 515 list of InputValueDefinitionNode instance as value 516 :rtype: SchemaNode 517 """ 518 # pylint: disable=no-self-use 519 return SchemaNode( 520 type="arguments_definition", 521 value=[child.value for child in tree.children], 522 ) 523 524 def directive_location(self, tree: "Tree") -> "SchemaNode": 525 """ 526 Creates and returns a SchemaNode instance of type "directive_location" 527 with a NameNode instance as value (extracted from the parsing of the 528 tree instance). 529 :param tree: the Tree to parse in order to extract the proper node 530 :type tree: Tree 531 :return: a SchemaNode instance of type "directive_location" with a 532 NameNode instance as value 533 :rtype: SchemaNode 534 """ 535 # pylint: disable=no-self-use 536 return SchemaNode( 537 type="directive_location", value=lark_to_name_node(tree) 538 ) 539 540 def directive_locations(self, tree: "Tree") -> "SchemaNode": 541 """ 542 Creates and returns a SchemaNode instance of type "directive_locations" 543 with a list of NameNode instance as value (extracted from the parsing 544 of the tree instance). 545 :param tree: the Tree to parse in order to extract the proper node 546 :return: a SchemaNode instance of type "directive_locations" with a 547 list of NameNode instance as value 548 """ 549 # pylint: disable=no-self-use 550 return SchemaNode( 551 type="directive_locations", 552 value=[child.value for child in tree.children], 553 ) 554 555 def directive_definition(self, tree: "Tree") -> "SchemaNode": 556 """ 557 Creates and returns a SchemaNode instance of type 558 "directive_definition" with a DirectiveDefinitionNode instance as value 559 (extracted from the parsing of the tree instance). 560 :param tree: the Tree to parse in order to extract the proper node 561 :type tree: Tree 562 :return: a SchemaNode instance of type "directive_definition" with a 563 DirectiveDefinitionNode instance as value 564 :rtype: SchemaNode 565 """ 566 # pylint: disable=no-self-use 567 return SchemaNode( 568 type="directive_definition", 569 value=lark_to_directive_definition_node(tree), 570 ) 571 572 def implements_interfaces(self, tree: "Tree") -> "SchemaNode": 573 """ 574 Creates and returns a SchemaNode instance of type 575 "implements_interfaces" with a list of NamedTypeNode instance as value 576 (extracted from the parsing of the tree instance). 577 :param tree: the Tree to parse in order to extract the proper node 578 :type tree: Tree 579 :return: a SchemaNode instance of type "implements_interfaces" with a 580 list of NamedTypeNode instance as value 581 :rtype: SchemaNode 582 """ 583 # pylint: disable=no-self-use 584 return SchemaNode( 585 type="implements_interfaces", 586 value=lark_to_implements_interfaces_node(tree), 587 ) 588 589 def field_definition(self, tree: "Tree") -> "SchemaNode": 590 """ 591 Creates and returns a SchemaNode instance of type "field_definition" 592 with a FieldDefinitionNode instance as value (extracted from the 593 parsing of the tree instance). 594 :param tree: the Tree to parse in order to extract the proper node 595 :type tree: Tree 596 :return: a SchemaNode instance of type "field_definition" with a 597 FieldDefinitionNode instance as value 598 :rtype: SchemaNode 599 """ 600 # pylint: disable=no-self-use 601 return SchemaNode( 602 type="field_definition", value=lark_to_field_definition_node(tree) 603 ) 604 605 def fields_definition(self, tree: "Tree") -> "SchemaNode": 606 """ 607 Creates and returns a SchemaNode instance of type "fields_definition" 608 with a list of FieldDefinitionNode instance as value (extracted from 609 the parsing of the tree instance). 610 :param tree: the Tree to parse in order to extract the proper node 611 :type tree: Tree 612 :return: a SchemaNode instance of type "fields_definition" with a list 613 of FieldDefinitionNode instance as value 614 :rtype: SchemaNode 615 """ 616 # pylint: disable=no-self-use 617 return SchemaNode( 618 type="fields_definition", 619 value=[child.value for child in tree.children], 620 ) 621 622 def object_type_definition(self, tree: "Tree") -> "SchemaNode": 623 """ 624 Creates and returns a SchemaNode instance of type 625 "object_type_definition" with an ObjectTypeDefinitionNode instance as 626 value (extracted from the parsing of the tree instance). 627 :param tree: the Tree to parse in order to extract the proper node 628 :type tree: Tree 629 :return: a SchemaNode instance of type "object_type_definition" with an 630 ObjectTypeDefinitionNode instance as value 631 :rtype: SchemaNode 632 """ 633 # pylint: disable=no-self-use 634 return SchemaNode( 635 type="object_type_definition", 636 value=lark_to_object_type_definition_node(tree), 637 ) 638 639 def interface_type_definition(self, tree: "Tree") -> "SchemaNode": 640 """ 641 Creates and returns a SchemaNode instance of type 642 "interface_type_definition" with an InterfaceTypeDefinitionNode 643 instance as value (extracted from the parsing of the tree instance). 644 :param tree: the Tree to parse in order to extract the proper node 645 :type tree: Tree 646 :return: a SchemaNode instance of type "interface_type_definition" with 647 an InterfaceTypeDefinitionNode instance as value 648 :rtype: SchemaNode 649 """ 650 # pylint: disable=no-self-use 651 return SchemaNode( 652 type="interface_type_definition", 653 value=lark_to_interface_type_definition_node(tree), 654 ) 655 656 def union_member_types(self, tree: "Tree") -> "SchemaNode": 657 """ 658 Creates and returns a SchemaNode instance of type "union_member_types" 659 with a list of NamedTypeNode instance as value (extracted from the 660 parsing of the tree instance). 661 :param tree: the Tree to parse in order to extract the proper node 662 :type tree: Tree 663 :return: a SchemaNode instance of type "union_member_types" with a list 664 of NamedTypeNode instance as value 665 :rtype: SchemaNode 666 """ 667 # pylint: disable=no-self-use 668 return SchemaNode( 669 type="union_member_types", 670 value=[child.value for child in tree.children], 671 ) 672 673 def union_type_definition(self, tree: "Tree") -> "SchemaNode": 674 """ 675 Creates and returns a SchemaNode instance of type 676 "union_type_definition" with an UnionTypeDefinitionNode instance as 677 value (extracted from the parsing of the tree instance). 678 :param tree: the Tree to parse in order to extract the proper node 679 :type tree: Tree 680 :return: a SchemaNode instance of type "union_type_definition" with an 681 UnionTypeDefinitionNode instance as value 682 :rtype: SchemaNode 683 """ 684 # pylint: disable=no-self-use 685 return SchemaNode( 686 type="union_type_definition", 687 value=lark_to_union_type_definition_node(tree), 688 ) 689 690 def enum_value_definition(self, tree: "Tree") -> "SchemaNode": 691 """ 692 Creates and returns a SchemaNode instance of type 693 "enum_value_definition" with an EnumValueDefinitionNode instance as 694 value (extracted from the parsing of the tree instance). 695 :param tree: the Tree to parse in order to extract the proper node 696 :type tree: Tree 697 :return: a SchemaNode instance of type "enum_value_definition" with an 698 EnumValueDefinitionNode instance as value 699 :rtype: SchemaNode 700 """ 701 # pylint: disable=no-self-use 702 return SchemaNode( 703 type="enum_value_definition", 704 value=lark_to_enum_value_definition_node(tree), 705 ) 706 707 def enum_values_definition(self, tree: "Tree") -> "SchemaNode": 708 """ 709 Creates and returns a SchemaNode instance of type 710 "enum_values_definition" with a list of EnumValueDefinitionNode 711 instance as value (extracted from the parsing of the tree instance). 712 :param tree: the Tree to parse in order to extract the proper node 713 :type tree: Tree 714 :return: a SchemaNode instance of type "enum_values_definition" with a 715 list of EnumValueDefinitionNode instance as value 716 :rtype: SchemaNode 717 """ 718 # pylint: disable=no-self-use 719 return SchemaNode( 720 type="enum_values_definition", 721 value=[child.value for child in tree.children], 722 ) 723 724 def enum_type_definition(self, tree: "Tree") -> "SchemaNode": 725 """ 726 Creates and returns a SchemaNode instance of type 727 "enum_type_definition" with an EnumTypeDefinitionNode instance as value 728 (extracted from the parsing of the tree instance). 729 :param tree: the Tree to parse in order to extract the proper node 730 :type tree: Tree 731 :return: a SchemaNode instance of type "enum_type_definition" with an 732 EnumTypeDefinitionNode instance as value 733 :rtype: SchemaNode 734 """ 735 # pylint: disable=no-self-use 736 return SchemaNode( 737 type="enum_type_definition", 738 value=lark_to_enum_type_definition_node(tree), 739 ) 740 741 def input_fields_definition(self, tree: "Tree") -> "SchemaNode": 742 """ 743 Creates and returns a SchemaNode instance of type 744 "input_fields_definition" with a list of InputValueDefinitionNode 745 instance as value (extracted from the parsing of the tree instance). 746 :param tree: the Tree to parse in order to extract the proper node 747 :type tree: Tree 748 :return: a SchemaNode instance of type "input_fields_definition" with a 749 list of InputValueDefinitionNode instance as value 750 :rtype: SchemaNode 751 """ 752 # pylint: disable=no-self-use 753 return SchemaNode( 754 type="input_fields_definition", 755 value=[child.value for child in tree.children], 756 ) 757 758 def input_object_type_definition(self, tree: "Tree") -> "SchemaNode": 759 """ 760 Creates and returns a SchemaNode instance of type 761 "input_object_type_definition" with an InputObjectTypeDefinitionNode 762 instance as value (extracted from the parsing of the tree instance). 763 :param tree: the Tree to parse in order to extract the proper node 764 :type tree: Tree 765 :return: a SchemaNode instance of type "input_object_type_definition" 766 with an InputObjectTypeDefinitionNode instance as value 767 :rtype: SchemaNode 768 """ 769 # pylint: disable=no-self-use 770 return SchemaNode( 771 type="input_object_type_definition", 772 value=lark_to_input_object_type_definition_node(tree), 773 ) 774 775 def schema_extension(self, tree: "Tree") -> "SchemaNode": 776 """ 777 Creates and returns a SchemaNode instance of type "schema_extension" 778 with a SchemaExtensionNode instance as value (extracted from the 779 parsing of the tree instance). 780 :param tree: the Tree to parse in order to extract the proper node 781 :type tree: Tree 782 :return: a SchemaNode instance of type "schema_extension" with a 783 SchemaExtensionNode instance as value 784 :rtype: SchemaNode 785 """ 786 # pylint: disable=no-self-use 787 return SchemaNode( 788 type="schema_extension", value=lark_to_schema_extension_node(tree) 789 ) 790 791 def scalar_type_extension(self, tree: "Tree") -> "SchemaNode": 792 """ 793 Creates and returns a SchemaNode instance of type 794 "scalar_type_extension" with a ScalarTypeExtensionNode instance as 795 value (extracted from the parsing of the tree instance). 796 :param tree: the Tree to parse in order to extract the proper node 797 :type tree: Tree 798 :return: a SchemaNode instance of type "scalar_type_extension" with a 799 ScalarTypeExtensionNode instance as value 800 :rtype: SchemaNode 801 """ 802 # pylint: disable=no-self-use 803 return SchemaNode( 804 type="scalar_type_extension", 805 value=lark_to_scalar_type_extension_node(tree), 806 ) 807 808 def object_type_extension(self, tree: "Tree") -> "SchemaNode": 809 """ 810 Creates and returns a SchemaNode instance of type 811 "object_type_extension" with an ObjectTypeExtensionNode instance as 812 value (extracted from the parsing of the tree instance). 813 :param tree: the Tree to parse in order to extract the proper node 814 :type tree: Tree 815 :return: a SchemaNode instance of type "object_type_extension" with an 816 ObjectTypeExtensionNode instance as value 817 :rtype: SchemaNode 818 """ 819 # pylint: disable=no-self-use 820 return SchemaNode( 821 type="object_type_extension", 822 value=lark_to_object_type_extension_node(tree), 823 ) 824 825 def interface_type_extension(self, tree: "Tree") -> "SchemaNode": 826 """ 827 Creates and returns a SchemaNode instance of type 828 "interface_type_extension" with an InterfaceTypeExtensionNode instance 829 as value (extracted from the parsing of the tree instance). 830 :param tree: the Tree to parse in order to extract the proper node 831 :type tree: Tree 832 :return: a SchemaNode instance of type "interface_type_extension" with 833 an InterfaceTypeExtensionNode instance as value 834 :rtype: SchemaNode 835 """ 836 # pylint: disable=no-self-use 837 return SchemaNode( 838 type="interface_type_extension", 839 value=lark_to_interface_type_extension_node(tree), 840 ) 841 842 def union_type_extension(self, tree: "Tree") -> "SchemaNode": 843 """ 844 Creates and returns a SchemaNode instance of type 845 "union_type_extension" with an UnionTypeExtensionNode instance as value 846 (extracted from the parsing of the tree instance). 847 :param tree: the Tree to parse in order to extract the proper node 848 :type tree: Tree 849 :return: a SchemaNode instance of type "union_type_extension" with an 850 UnionTypeExtensionNode instance as value 851 :rtype: SchemaNode 852 """ 853 # pylint: disable=no-self-use 854 return SchemaNode( 855 type="union_type_extension", 856 value=lark_to_union_type_extension_node(tree), 857 ) 858 859 def enum_type_extension(self, tree: "Tree") -> "SchemaNode": 860 """ 861 Creates and returns a SchemaNode instance of type "enum_type_extension" 862 with an EnumTypeExtensionNode instance as value (extracted from the 863 parsing of the tree instance). 864 :param tree: the Tree to parse in order to extract the proper node 865 :type tree: Tree 866 :return: a SchemaNode instance of type "enum_type_extension" with an 867 EnumTypeExtensionNode instance as value 868 :rtype: SchemaNode 869 """ 870 # pylint: disable=no-self-use 871 return SchemaNode( 872 type="enum_type_extension", 873 value=lark_to_enum_type_extension_node(tree), 874 ) 875 876 def input_object_type_extension(self, tree: "Tree") -> "SchemaNode": 877 """ 878 Creates and returns a SchemaNode instance of type 879 "input_object_type_extension" with an InputObjectTypeExtensionNode 880 instance 881 as value (extracted from the parsing of the tree instance). 882 :param tree: the Tree to parse in order to extract the proper node 883 :type tree: Tree 884 :return: a SchemaNode instance of type "input_object_type_extension" 885 with an InputObjectTypeExtensionNode instance as value 886 :rtype: SchemaNode 887 """ 888 # pylint: disable=no-self-use 889 return SchemaNode( 890 type="input_object_type_extension", 891 value=lark_to_input_object_type_extension_node(tree), 892 ) 893 894 def document(self, tree: "Tree") -> "Tree": 895 """ 896 Extracts the DocumentNode from the parsing of the tree instance and set 897 it to the document node attribute instance. 898 :param tree: the Tree to parse in order to extract the proper node 899 :type tree: Tree 900 :return: the tree instance 901 :rtype: Tree 902 """ 903 self.document_node = lark_to_document_node(tree) 904 return tree 905