1"""GraphQL-core 2 3The primary :mod:`graphql` package includes everything you need to define a GraphQL 4schema and fulfill GraphQL requests. 5 6GraphQL-core provides a reference implementation for the GraphQL specification 7but is also a useful utility for operating on GraphQL files and building sophisticated 8tools. 9 10This top-level package exports a general purpose function for fulfilling all steps 11of the GraphQL specification in a single operation, but also includes utilities 12for every part of the GraphQL specification: 13 14 - Parsing the GraphQL language. 15 - Building a GraphQL type schema. 16 - Validating a GraphQL request against a type schema. 17 - Executing a GraphQL request against a type schema. 18 19This also includes utility functions for operating on GraphQL types and GraphQL 20documents to facilitate building tools. 21 22You may also import from each sub-package directly. For example, the following two 23import statements are equivalent:: 24 25 from graphql import parse 26 from graphql.language import parse 27 28The sub-packages of GraphQL-core 3 are: 29 30 - :mod:`graphql.language`: Parse and operate on the GraphQL language. 31 - :mod:`graphql.type`: Define GraphQL types and schema. 32 - :mod:`graphql.validation`: The Validation phase of fulfilling a GraphQL result. 33 - :mod:`graphql.execution`: The Execution phase of fulfilling a GraphQL request. 34 - :mod:`graphql.error`: Creating and formatting GraphQL errors. 35 - :mod:`graphql.utilities`: 36 Common useful computations upon the GraphQL language and type objects. 37 - :mod:`graphql.subscription`: Subscribe to data updates. 38""" 39 40# The GraphQL-core 3 and GraphQL.js version info. 41 42from .version import version, version_info, version_js, version_info_js 43 44# The primary entry point into fulfilling a GraphQL request. 45 46from .graphql import graphql, graphql_sync 47 48# Create and operate on GraphQL type definitions and schema. 49from .type import ( 50 # Definitions 51 GraphQLSchema, 52 GraphQLDirective, 53 GraphQLScalarType, 54 GraphQLObjectType, 55 GraphQLInterfaceType, 56 GraphQLUnionType, 57 GraphQLEnumType, 58 GraphQLInputObjectType, 59 GraphQLList, 60 GraphQLNonNull, 61 # Standard GraphQL Scalars 62 specified_scalar_types, 63 GraphQLInt, 64 GraphQLFloat, 65 GraphQLString, 66 GraphQLBoolean, 67 GraphQLID, 68 # Built-in Directives defined by the Spec 69 specified_directives, 70 GraphQLIncludeDirective, 71 GraphQLSkipDirective, 72 GraphQLDeprecatedDirective, 73 GraphQLSpecifiedByDirective, 74 # "Enum" of Type Kinds 75 TypeKind, 76 # Constant Deprecation Reason 77 DEFAULT_DEPRECATION_REASON, 78 # GraphQL Types for introspection. 79 introspection_types, 80 # Meta-field definitions. 81 SchemaMetaFieldDef, 82 TypeMetaFieldDef, 83 TypeNameMetaFieldDef, 84 # Predicates 85 is_schema, 86 is_directive, 87 is_type, 88 is_scalar_type, 89 is_object_type, 90 is_interface_type, 91 is_union_type, 92 is_enum_type, 93 is_input_object_type, 94 is_list_type, 95 is_non_null_type, 96 is_input_type, 97 is_output_type, 98 is_leaf_type, 99 is_composite_type, 100 is_abstract_type, 101 is_wrapping_type, 102 is_nullable_type, 103 is_named_type, 104 is_required_argument, 105 is_required_input_field, 106 is_specified_scalar_type, 107 is_introspection_type, 108 is_specified_directive, 109 # Assertions 110 assert_schema, 111 assert_directive, 112 assert_type, 113 assert_scalar_type, 114 assert_object_type, 115 assert_interface_type, 116 assert_union_type, 117 assert_enum_type, 118 assert_input_object_type, 119 assert_list_type, 120 assert_non_null_type, 121 assert_input_type, 122 assert_output_type, 123 assert_leaf_type, 124 assert_composite_type, 125 assert_abstract_type, 126 assert_wrapping_type, 127 assert_nullable_type, 128 assert_named_type, 129 # Un-modifiers 130 get_nullable_type, 131 get_named_type, 132 # Validate GraphQL schema. 133 validate_schema, 134 assert_valid_schema, 135 # Types 136 GraphQLType, 137 GraphQLInputType, 138 GraphQLOutputType, 139 GraphQLLeafType, 140 GraphQLCompositeType, 141 GraphQLAbstractType, 142 GraphQLWrappingType, 143 GraphQLNullableType, 144 GraphQLNamedType, 145 Thunk, 146 GraphQLArgument, 147 GraphQLArgumentMap, 148 GraphQLEnumValue, 149 GraphQLEnumValueMap, 150 GraphQLField, 151 GraphQLFieldMap, 152 GraphQLFieldResolver, 153 GraphQLInputField, 154 GraphQLInputFieldMap, 155 GraphQLScalarSerializer, 156 GraphQLScalarValueParser, 157 GraphQLScalarLiteralParser, 158 GraphQLIsTypeOfFn, 159 GraphQLResolveInfo, 160 ResponsePath, 161 GraphQLTypeResolver, 162) 163 164# Parse and operate on GraphQL language source files. 165from .language import ( 166 Source, 167 get_location, 168 # Print source location 169 print_location, 170 print_source_location, 171 # Lex 172 Lexer, 173 TokenKind, 174 # Parse 175 parse, 176 parse_value, 177 parse_type, 178 # Print 179 print_ast, 180 # Visit 181 visit, 182 ParallelVisitor, 183 Visitor, 184 VisitorAction, 185 BREAK, 186 SKIP, 187 REMOVE, 188 IDLE, 189 DirectiveLocation, 190 # Predicates 191 is_definition_node, 192 is_executable_definition_node, 193 is_selection_node, 194 is_value_node, 195 is_type_node, 196 is_type_system_definition_node, 197 is_type_definition_node, 198 is_type_system_extension_node, 199 is_type_extension_node, 200 # Types 201 SourceLocation, 202 Location, 203 Token, 204 # AST nodes 205 Node, 206 # Each kind of AST node 207 NameNode, 208 DocumentNode, 209 DefinitionNode, 210 ExecutableDefinitionNode, 211 OperationDefinitionNode, 212 OperationType, 213 VariableDefinitionNode, 214 VariableNode, 215 SelectionSetNode, 216 SelectionNode, 217 FieldNode, 218 ArgumentNode, 219 FragmentSpreadNode, 220 InlineFragmentNode, 221 FragmentDefinitionNode, 222 ValueNode, 223 IntValueNode, 224 FloatValueNode, 225 StringValueNode, 226 BooleanValueNode, 227 NullValueNode, 228 EnumValueNode, 229 ListValueNode, 230 ObjectValueNode, 231 ObjectFieldNode, 232 DirectiveNode, 233 TypeNode, 234 NamedTypeNode, 235 ListTypeNode, 236 NonNullTypeNode, 237 TypeSystemDefinitionNode, 238 SchemaDefinitionNode, 239 OperationTypeDefinitionNode, 240 TypeDefinitionNode, 241 ScalarTypeDefinitionNode, 242 ObjectTypeDefinitionNode, 243 FieldDefinitionNode, 244 InputValueDefinitionNode, 245 InterfaceTypeDefinitionNode, 246 UnionTypeDefinitionNode, 247 EnumTypeDefinitionNode, 248 EnumValueDefinitionNode, 249 InputObjectTypeDefinitionNode, 250 DirectiveDefinitionNode, 251 TypeSystemExtensionNode, 252 SchemaExtensionNode, 253 TypeExtensionNode, 254 ScalarTypeExtensionNode, 255 ObjectTypeExtensionNode, 256 InterfaceTypeExtensionNode, 257 UnionTypeExtensionNode, 258 EnumTypeExtensionNode, 259 InputObjectTypeExtensionNode, 260) 261 262# Execute GraphQL documents. 263from .execution import ( 264 execute, 265 execute_sync, 266 default_field_resolver, 267 default_type_resolver, 268 get_directive_values, 269 # Types 270 ExecutionContext, 271 ExecutionResult, 272 # Middleware 273 Middleware, 274 MiddlewareManager, 275) 276 277from .subscription import subscribe, create_source_event_stream, MapAsyncIterator 278 279 280# Validate GraphQL queries. 281from .validation import ( 282 validate, 283 ValidationContext, 284 ValidationRule, 285 ASTValidationRule, 286 SDLValidationRule, 287 # All validation rules in the GraphQL Specification. 288 specified_rules, 289 # Individual validation rules. 290 ExecutableDefinitionsRule, 291 FieldsOnCorrectTypeRule, 292 FragmentsOnCompositeTypesRule, 293 KnownArgumentNamesRule, 294 KnownDirectivesRule, 295 KnownFragmentNamesRule, 296 KnownTypeNamesRule, 297 LoneAnonymousOperationRule, 298 NoFragmentCyclesRule, 299 NoUndefinedVariablesRule, 300 NoUnusedFragmentsRule, 301 NoUnusedVariablesRule, 302 OverlappingFieldsCanBeMergedRule, 303 PossibleFragmentSpreadsRule, 304 ProvidedRequiredArgumentsRule, 305 ScalarLeafsRule, 306 SingleFieldSubscriptionsRule, 307 UniqueArgumentNamesRule, 308 UniqueDirectivesPerLocationRule, 309 UniqueFragmentNamesRule, 310 UniqueInputFieldNamesRule, 311 UniqueOperationNamesRule, 312 UniqueVariableNamesRule, 313 ValuesOfCorrectTypeRule, 314 VariablesAreInputTypesRule, 315 VariablesInAllowedPositionRule, 316 # SDL-specific validation rules 317 LoneSchemaDefinitionRule, 318 UniqueOperationTypesRule, 319 UniqueTypeNamesRule, 320 UniqueEnumValueNamesRule, 321 UniqueFieldDefinitionNamesRule, 322 UniqueDirectiveNamesRule, 323 PossibleTypeExtensionsRule, 324 # Custom validation rules 325 NoDeprecatedCustomRule, 326 NoSchemaIntrospectionCustomRule, 327) 328 329# Create, format, and print GraphQL errors. 330from .error import ( 331 GraphQLError, 332 GraphQLSyntaxError, 333 located_error, 334 format_error, 335 print_error, 336) 337 338# Utilities for operating on GraphQL type schema and parsed sources. 339from .utilities import ( 340 # Produce the GraphQL query recommended for a full schema introspection. 341 # Accepts optional IntrospectionOptions. 342 get_introspection_query, 343 # Get the target Operation from a Document. 344 get_operation_ast, 345 # Get the Type for the target Operation AST. 346 get_operation_root_type, 347 # Convert a GraphQLSchema to an IntrospectionQuery. 348 introspection_from_schema, 349 # Build a GraphQLSchema from an introspection result. 350 build_client_schema, 351 # Build a GraphQLSchema from a parsed GraphQL Schema language AST. 352 build_ast_schema, 353 # Build a GraphQLSchema from a GraphQL schema language document. 354 build_schema, 355 # @deprecated: Get the description from a schema AST node. 356 get_description, 357 # Extend an existing GraphQLSchema from a parsed GraphQL Schema language AST. 358 extend_schema, 359 # Sort a GraphQLSchema. 360 lexicographic_sort_schema, 361 # Print a GraphQLSchema to GraphQL Schema language. 362 print_schema, 363 # Print a GraphQLType to GraphQL Schema language. 364 print_type, 365 # Prints the built-in introspection schema in the Schema Language format. 366 print_introspection_schema, 367 # Create a GraphQLType from a GraphQL language AST. 368 type_from_ast, 369 # Create a Python value from a GraphQL language AST with a Type. 370 value_from_ast, 371 # Create a Python value from a GraphQL language AST without a Type. 372 value_from_ast_untyped, 373 # Create a GraphQL language AST from a Python value. 374 ast_from_value, 375 # A helper to use within recursive-descent visitors which need to be aware of the 376 # GraphQL type system. 377 TypeInfo, 378 TypeInfoVisitor, 379 # Coerce a Python value to a GraphQL type, or produce errors. 380 coerce_input_value, 381 # Concatenates multiple ASTs together. 382 concat_ast, 383 # Separate an AST into an AST per Operation. 384 separate_operations, 385 # Strip characters that are not significant to the validity or execution 386 # of a GraphQL document. 387 strip_ignored_characters, 388 # Comparators for types 389 is_equal_type, 390 is_type_sub_type_of, 391 do_types_overlap, 392 # Assert a string is a valid GraphQL name. 393 assert_valid_name, 394 # Determine if a string is a valid GraphQL name. 395 is_valid_name_error, 396 # Compare two GraphQLSchemas and detect breaking changes. 397 BreakingChange, 398 BreakingChangeType, 399 DangerousChange, 400 DangerousChangeType, 401 find_breaking_changes, 402 find_dangerous_changes, 403 # Report all deprecated usages within a GraphQL document (deprecated). 404 find_deprecated_usages, 405) 406 407# Utilities for compatibility with the Python language. 408from .pyutils import Undefined, UndefinedType 409 410INVALID = Undefined # deprecated alias 411 412# The GraphQL-core version info. 413__version__ = version 414__version_info__ = version_info 415 416# The GraphQL.js version info. 417__version_js__ = version_js 418__version_info_js__ = version_info_js 419 420 421__all__ = [ 422 "version", 423 "version_info", 424 "version_js", 425 "version_info_js", 426 "graphql", 427 "graphql_sync", 428 "GraphQLSchema", 429 "GraphQLDirective", 430 "GraphQLScalarType", 431 "GraphQLObjectType", 432 "GraphQLInterfaceType", 433 "GraphQLUnionType", 434 "GraphQLEnumType", 435 "GraphQLInputObjectType", 436 "GraphQLList", 437 "GraphQLNonNull", 438 "specified_scalar_types", 439 "GraphQLInt", 440 "GraphQLFloat", 441 "GraphQLString", 442 "GraphQLBoolean", 443 "GraphQLID", 444 "specified_directives", 445 "GraphQLIncludeDirective", 446 "GraphQLSkipDirective", 447 "GraphQLDeprecatedDirective", 448 "GraphQLSpecifiedByDirective", 449 "TypeKind", 450 "DEFAULT_DEPRECATION_REASON", 451 "introspection_types", 452 "SchemaMetaFieldDef", 453 "TypeMetaFieldDef", 454 "TypeNameMetaFieldDef", 455 "is_schema", 456 "is_directive", 457 "is_type", 458 "is_scalar_type", 459 "is_object_type", 460 "is_interface_type", 461 "is_union_type", 462 "is_enum_type", 463 "is_input_object_type", 464 "is_list_type", 465 "is_non_null_type", 466 "is_input_type", 467 "is_output_type", 468 "is_leaf_type", 469 "is_composite_type", 470 "is_abstract_type", 471 "is_wrapping_type", 472 "is_nullable_type", 473 "is_named_type", 474 "is_required_argument", 475 "is_required_input_field", 476 "is_specified_scalar_type", 477 "is_introspection_type", 478 "is_specified_directive", 479 "assert_schema", 480 "assert_directive", 481 "assert_type", 482 "assert_scalar_type", 483 "assert_object_type", 484 "assert_interface_type", 485 "assert_union_type", 486 "assert_enum_type", 487 "assert_input_object_type", 488 "assert_list_type", 489 "assert_non_null_type", 490 "assert_input_type", 491 "assert_output_type", 492 "assert_leaf_type", 493 "assert_composite_type", 494 "assert_abstract_type", 495 "assert_wrapping_type", 496 "assert_nullable_type", 497 "assert_named_type", 498 "get_nullable_type", 499 "get_named_type", 500 "validate_schema", 501 "assert_valid_schema", 502 "GraphQLType", 503 "GraphQLInputType", 504 "GraphQLOutputType", 505 "GraphQLLeafType", 506 "GraphQLCompositeType", 507 "GraphQLAbstractType", 508 "GraphQLWrappingType", 509 "GraphQLNullableType", 510 "GraphQLNamedType", 511 "Thunk", 512 "GraphQLArgument", 513 "GraphQLArgumentMap", 514 "GraphQLEnumValue", 515 "GraphQLEnumValueMap", 516 "GraphQLField", 517 "GraphQLFieldMap", 518 "GraphQLFieldResolver", 519 "GraphQLInputField", 520 "GraphQLInputFieldMap", 521 "GraphQLScalarSerializer", 522 "GraphQLScalarValueParser", 523 "GraphQLScalarLiteralParser", 524 "GraphQLIsTypeOfFn", 525 "GraphQLResolveInfo", 526 "ResponsePath", 527 "GraphQLTypeResolver", 528 "Source", 529 "get_location", 530 "print_location", 531 "print_source_location", 532 "Lexer", 533 "TokenKind", 534 "parse", 535 "parse_value", 536 "parse_type", 537 "print_ast", 538 "visit", 539 "ParallelVisitor", 540 "TypeInfoVisitor", 541 "Visitor", 542 "VisitorAction", 543 "BREAK", 544 "SKIP", 545 "REMOVE", 546 "IDLE", 547 "DirectiveLocation", 548 "is_definition_node", 549 "is_executable_definition_node", 550 "is_selection_node", 551 "is_value_node", 552 "is_type_node", 553 "is_type_system_definition_node", 554 "is_type_definition_node", 555 "is_type_system_extension_node", 556 "is_type_extension_node", 557 "SourceLocation", 558 "Location", 559 "Token", 560 "Node", 561 "NameNode", 562 "DocumentNode", 563 "DefinitionNode", 564 "ExecutableDefinitionNode", 565 "OperationDefinitionNode", 566 "OperationType", 567 "VariableDefinitionNode", 568 "VariableNode", 569 "SelectionSetNode", 570 "SelectionNode", 571 "FieldNode", 572 "ArgumentNode", 573 "FragmentSpreadNode", 574 "InlineFragmentNode", 575 "FragmentDefinitionNode", 576 "ValueNode", 577 "IntValueNode", 578 "FloatValueNode", 579 "StringValueNode", 580 "BooleanValueNode", 581 "NullValueNode", 582 "EnumValueNode", 583 "ListValueNode", 584 "ObjectValueNode", 585 "ObjectFieldNode", 586 "DirectiveNode", 587 "TypeNode", 588 "NamedTypeNode", 589 "ListTypeNode", 590 "NonNullTypeNode", 591 "TypeSystemDefinitionNode", 592 "SchemaDefinitionNode", 593 "OperationTypeDefinitionNode", 594 "TypeDefinitionNode", 595 "ScalarTypeDefinitionNode", 596 "ObjectTypeDefinitionNode", 597 "FieldDefinitionNode", 598 "InputValueDefinitionNode", 599 "InterfaceTypeDefinitionNode", 600 "UnionTypeDefinitionNode", 601 "EnumTypeDefinitionNode", 602 "EnumValueDefinitionNode", 603 "InputObjectTypeDefinitionNode", 604 "DirectiveDefinitionNode", 605 "TypeSystemExtensionNode", 606 "SchemaExtensionNode", 607 "TypeExtensionNode", 608 "ScalarTypeExtensionNode", 609 "ObjectTypeExtensionNode", 610 "InterfaceTypeExtensionNode", 611 "UnionTypeExtensionNode", 612 "EnumTypeExtensionNode", 613 "InputObjectTypeExtensionNode", 614 "execute", 615 "execute_sync", 616 "default_field_resolver", 617 "default_type_resolver", 618 "get_directive_values", 619 "ExecutionContext", 620 "ExecutionResult", 621 "Middleware", 622 "MiddlewareManager", 623 "subscribe", 624 "create_source_event_stream", 625 "MapAsyncIterator", 626 "validate", 627 "ValidationContext", 628 "ValidationRule", 629 "ASTValidationRule", 630 "SDLValidationRule", 631 "specified_rules", 632 "ExecutableDefinitionsRule", 633 "FieldsOnCorrectTypeRule", 634 "FragmentsOnCompositeTypesRule", 635 "KnownArgumentNamesRule", 636 "KnownDirectivesRule", 637 "KnownFragmentNamesRule", 638 "KnownTypeNamesRule", 639 "LoneAnonymousOperationRule", 640 "NoFragmentCyclesRule", 641 "NoUndefinedVariablesRule", 642 "NoUnusedFragmentsRule", 643 "NoUnusedVariablesRule", 644 "OverlappingFieldsCanBeMergedRule", 645 "PossibleFragmentSpreadsRule", 646 "ProvidedRequiredArgumentsRule", 647 "ScalarLeafsRule", 648 "SingleFieldSubscriptionsRule", 649 "UniqueArgumentNamesRule", 650 "UniqueDirectivesPerLocationRule", 651 "UniqueFragmentNamesRule", 652 "UniqueInputFieldNamesRule", 653 "UniqueOperationNamesRule", 654 "UniqueVariableNamesRule", 655 "ValuesOfCorrectTypeRule", 656 "VariablesAreInputTypesRule", 657 "VariablesInAllowedPositionRule", 658 "LoneSchemaDefinitionRule", 659 "UniqueOperationTypesRule", 660 "UniqueTypeNamesRule", 661 "UniqueEnumValueNamesRule", 662 "UniqueFieldDefinitionNamesRule", 663 "UniqueDirectiveNamesRule", 664 "PossibleTypeExtensionsRule", 665 "NoDeprecatedCustomRule", 666 "NoSchemaIntrospectionCustomRule", 667 "GraphQLError", 668 "GraphQLSyntaxError", 669 "located_error", 670 "format_error", 671 "print_error", 672 "get_introspection_query", 673 "get_operation_ast", 674 "get_operation_root_type", 675 "introspection_from_schema", 676 "build_client_schema", 677 "build_ast_schema", 678 "build_schema", 679 "get_description", 680 "extend_schema", 681 "lexicographic_sort_schema", 682 "print_schema", 683 "print_type", 684 "print_introspection_schema", 685 "type_from_ast", 686 "value_from_ast", 687 "value_from_ast_untyped", 688 "ast_from_value", 689 "TypeInfo", 690 "coerce_input_value", 691 "concat_ast", 692 "separate_operations", 693 "strip_ignored_characters", 694 "is_equal_type", 695 "is_type_sub_type_of", 696 "do_types_overlap", 697 "assert_valid_name", 698 "is_valid_name_error", 699 "find_breaking_changes", 700 "find_dangerous_changes", 701 "find_deprecated_usages", 702 "BreakingChange", 703 "BreakingChangeType", 704 "DangerousChange", 705 "DangerousChangeType", 706 "Undefined", 707 "UndefinedType", 708] 709