|
1 | 1 | ''' |
2 | | -GraphQL provides a Python implementation for the GraphQL specification |
| 2 | +GraphQL.js provides a reference implementation for the GraphQL specification |
3 | 3 | but is also a useful utility for operating on GraphQL files and building |
4 | 4 | sophisticated tools. |
5 | 5 |
|
|
14 | 14 |
|
15 | 15 | This also includes utility functions for operating on GraphQL types and |
16 | 16 | GraphQL documents to facilitate building tools. |
| 17 | +
|
| 18 | +You may also import from each sub-directory directly. For example, the |
| 19 | +following two import statements are equivalent: |
| 20 | +
|
| 21 | + from graphql import parse |
| 22 | + from graphql.language.base import parse |
17 | 23 | ''' |
18 | 24 |
|
19 | | -from .execution import ExecutionResult, execute |
20 | | -from .language.parser import parse |
21 | | -from .language.source import Source |
22 | | -from .validation import validate |
23 | | - |
24 | | - |
25 | | -def graphql(schema, request='', root=None, args=None, operation_name=None): |
26 | | - try: |
27 | | - source = Source(request, 'GraphQL request') |
28 | | - ast = parse(source) |
29 | | - validation_errors = validate(schema, ast) |
30 | | - if validation_errors: |
31 | | - return ExecutionResult( |
32 | | - errors=validation_errors, |
33 | | - invalid=True, |
34 | | - ) |
35 | | - return execute( |
36 | | - schema, |
37 | | - ast, |
38 | | - root, |
39 | | - operation_name=operation_name, |
40 | | - variable_values=args or {}, |
41 | | - ) |
42 | | - except Exception as e: |
43 | | - return ExecutionResult( |
44 | | - errors=[e], |
45 | | - invalid=True, |
46 | | - ) |
| 25 | + |
| 26 | +# The primary entry point into fulfilling a GraphQL request. |
| 27 | +from .graphql import ( |
| 28 | + graphql |
| 29 | +) |
| 30 | + |
| 31 | + |
| 32 | +# Create and operate on GraphQL type definitions and schema. |
| 33 | +from .type import ( # no import order |
| 34 | + GraphQLSchema, |
| 35 | + |
| 36 | + # Definitions |
| 37 | + GraphQLScalarType, |
| 38 | + GraphQLObjectType, |
| 39 | + GraphQLInterfaceType, |
| 40 | + GraphQLUnionType, |
| 41 | + GraphQLEnumType, |
| 42 | + GraphQLInputObjectType, |
| 43 | + GraphQLList, |
| 44 | + GraphQLNonNull, |
| 45 | + |
| 46 | + # Scalars |
| 47 | + GraphQLInt, |
| 48 | + GraphQLFloat, |
| 49 | + GraphQLString, |
| 50 | + GraphQLBoolean, |
| 51 | + GraphQLID, |
| 52 | + |
| 53 | + # Predicates |
| 54 | + is_type, |
| 55 | + is_input_type, |
| 56 | + is_output_type, |
| 57 | + is_leaf_type, |
| 58 | + is_composite_type, |
| 59 | + is_abstract_type, |
| 60 | + |
| 61 | + # Un-modifiers |
| 62 | + get_nullable_type, |
| 63 | + get_named_type, |
| 64 | +) |
| 65 | + |
| 66 | + |
| 67 | +# Parse and operate on GraphQL language source files. |
| 68 | +from .language.base import ( # no import order |
| 69 | + Source, |
| 70 | + get_location, |
| 71 | + |
| 72 | + # Parse |
| 73 | + parse, |
| 74 | + parse_value, |
| 75 | + |
| 76 | + # Print |
| 77 | + print_ast, |
| 78 | + |
| 79 | + # Visit |
| 80 | + visit, |
| 81 | + ParallelVisitor, |
| 82 | + TypeInfoVisitor, |
| 83 | + BREAK, |
| 84 | +) |
| 85 | + |
| 86 | + |
| 87 | +# Execute GraphQL queries. |
| 88 | +from .execution import ( # no import order |
| 89 | + execute, |
| 90 | +) |
| 91 | + |
| 92 | + |
| 93 | +# Validate GraphQL queries. |
| 94 | +from .validation import ( # no import order |
| 95 | + validate, |
| 96 | + specified_rules, |
| 97 | +) |
| 98 | + |
| 99 | +# Create and format GraphQL errors. |
| 100 | +from .error import ( # no import order |
| 101 | + GraphQLError, |
| 102 | + format_error, |
| 103 | +) |
| 104 | + |
| 105 | + |
| 106 | +# Utilities for operating on GraphQL type schema and parsed sources. |
| 107 | +from .utils.base import ( # no import order |
| 108 | + # The GraphQL query recommended for a full schema introspection. |
| 109 | + introspection_query, |
| 110 | + |
| 111 | + # Gets the target Operation from a Document |
| 112 | + get_operation_ast, |
| 113 | + |
| 114 | + # Build a GraphQLSchema from an introspection result. |
| 115 | + build_client_schema, |
| 116 | + |
| 117 | + # Build a GraphQLSchema from a parsed GraphQL Schema language AST. |
| 118 | + build_ast_schema, |
| 119 | + |
| 120 | + # Extends an existing GraphQLSchema from a parsed GraphQL Schema |
| 121 | + # language AST. |
| 122 | + extend_schema, |
| 123 | + |
| 124 | + # Print a GraphQLSchema to GraphQL Schema language. |
| 125 | + print_schema, |
| 126 | + |
| 127 | + # Create a GraphQLType from a GraphQL language AST. |
| 128 | + type_from_ast, |
| 129 | + |
| 130 | + # Create a JavaScript value from a GraphQL language AST. |
| 131 | + value_from_ast, |
| 132 | + |
| 133 | + # Create a GraphQL language AST from a JavaScript value. |
| 134 | + ast_from_value, |
| 135 | + |
| 136 | + # A helper to use within recursive-descent visitors which need to be aware of |
| 137 | + # the GraphQL type system. |
| 138 | + TypeInfo, |
| 139 | + |
| 140 | + # Determine if JavaScript values adhere to a GraphQL type. |
| 141 | + is_valid_value, |
| 142 | + |
| 143 | + # Determine if AST values adhere to a GraphQL type. |
| 144 | + is_valid_literal_value, |
| 145 | + |
| 146 | + # Concatenates multiple AST together. |
| 147 | + concat_ast, |
| 148 | + |
| 149 | + # Comparators for types |
| 150 | + is_equal_type, |
| 151 | + is_type_sub_type_of, |
| 152 | + do_types_overlap, |
| 153 | + |
| 154 | + # Asserts a string is a valid GraphQL name. |
| 155 | + assert_valid_name, |
| 156 | +) |
0 commit comments