Skip to content

Commit af57ecf

Browse files
committed
Updated imports and README with working examples
1 parent bff187a commit af57ecf

File tree

2 files changed

+93
-94
lines changed

2 files changed

+93
-94
lines changed

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ schema = GraphQLSchema(
5252
fields={
5353
'hello': GraphQLField(
5454
type= GraphQLString,
55-
resolve=lambda *_: 'world'
55+
resolver=lambda *_: 'world'
5656
)
5757
}
5858
)
@@ -72,10 +72,9 @@ query = '{ hello }'
7272
result = graphql(schema, query)
7373

7474
# Prints
75-
# {
76-
# "data": { "hello": "world" }
77-
# }
78-
print result
75+
# {'hello': 'world'} (as OrderedDict)
76+
77+
print result.data
7978
```
8079

8180
This runs a query fetching the one field defined. The `graphql` function will
@@ -88,13 +87,9 @@ query = '{ boyhowdy }'
8887
result = graphql(schema, query)
8988

9089
# Prints
91-
# {
92-
# "errors": [
93-
# { "message": "Cannot query field boyhowdy on RootQueryType",
94-
# "locations": [ { "line": 1, "column": 3 } ] }
95-
# ]
96-
# }
97-
print result
90+
# [GraphQLError('Cannot query field "boyhowdy" on type "RootQueryType".',)]
91+
92+
print result.errors
9893
```
9994

10095
### Executors

graphql/__init__.py

Lines changed: 86 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -25,134 +25,136 @@
2525

2626
# The primary entry point into fulfilling a GraphQL request.
2727
from .graphql import (
28-
graphql
28+
graphql
2929
)
3030

3131

3232
# Create and operate on GraphQL type definitions and schema.
3333
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,
34+
GraphQLSchema,
35+
36+
# Definitions
37+
GraphQLScalarType,
38+
GraphQLObjectType,
39+
GraphQLInterfaceType,
40+
GraphQLUnionType,
41+
GraphQLEnumType,
42+
GraphQLInputObjectType,
43+
GraphQLList,
44+
GraphQLNonNull,
45+
GraphQLField,
46+
GraphQLArgument,
47+
48+
# Scalars
49+
GraphQLInt,
50+
GraphQLFloat,
51+
GraphQLString,
52+
GraphQLBoolean,
53+
GraphQLID,
54+
55+
# Predicates
56+
is_type,
57+
is_input_type,
58+
is_output_type,
59+
is_leaf_type,
60+
is_composite_type,
61+
is_abstract_type,
62+
63+
# Un-modifiers
64+
get_nullable_type,
65+
get_named_type,
6466
)
6567

6668

6769
# Parse and operate on GraphQL language source files.
6870
from .language.base import ( # no import order
69-
Source,
70-
get_location,
71+
Source,
72+
get_location,
7173

72-
# Parse
73-
parse,
74-
parse_value,
74+
# Parse
75+
parse,
76+
parse_value,
7577

76-
# Print
77-
print_ast,
78+
# Print
79+
print_ast,
7880

79-
# Visit
80-
visit,
81-
ParallelVisitor,
82-
TypeInfoVisitor,
83-
BREAK,
81+
# Visit
82+
visit,
83+
ParallelVisitor,
84+
TypeInfoVisitor,
85+
BREAK,
8486
)
8587

8688

8789
# Execute GraphQL queries.
8890
from .execution import ( # no import order
89-
execute,
91+
execute,
9092
)
9193

9294

9395
# Validate GraphQL queries.
9496
from .validation import ( # no import order
95-
validate,
96-
specified_rules,
97+
validate,
98+
specified_rules,
9799
)
98100

99101
# Create and format GraphQL errors.
100102
from .error import (
101-
GraphQLError,
102-
format_error,
103+
GraphQLError,
104+
format_error,
103105
)
104106

105107

106108
# Utilities for operating on GraphQL type schema and parsed sources.
107109
from .utils.base import (
108-
# The GraphQL query recommended for a full schema introspection.
109-
introspection_query,
110+
# The GraphQL query recommended for a full schema introspection.
111+
introspection_query,
110112

111-
# Gets the target Operation from a Document
112-
get_operation_ast,
113+
# Gets the target Operation from a Document
114+
get_operation_ast,
113115

114-
# Build a GraphQLSchema from an introspection result.
115-
build_client_schema,
116+
# Build a GraphQLSchema from an introspection result.
117+
build_client_schema,
116118

117-
# Build a GraphQLSchema from a parsed GraphQL Schema language AST.
118-
build_ast_schema,
119+
# Build a GraphQLSchema from a parsed GraphQL Schema language AST.
120+
build_ast_schema,
119121

120-
# Extends an existing GraphQLSchema from a parsed GraphQL Schema
121-
# language AST.
122-
extend_schema,
122+
# Extends an existing GraphQLSchema from a parsed GraphQL Schema
123+
# language AST.
124+
extend_schema,
123125

124-
# Print a GraphQLSchema to GraphQL Schema language.
125-
print_schema,
126+
# Print a GraphQLSchema to GraphQL Schema language.
127+
print_schema,
126128

127-
# Create a GraphQLType from a GraphQL language AST.
128-
type_from_ast,
129+
# Create a GraphQLType from a GraphQL language AST.
130+
type_from_ast,
129131

130-
# Create a JavaScript value from a GraphQL language AST.
131-
value_from_ast,
132+
# Create a JavaScript value from a GraphQL language AST.
133+
value_from_ast,
132134

133-
# Create a GraphQL language AST from a JavaScript value.
134-
ast_from_value,
135+
# Create a GraphQL language AST from a JavaScript value.
136+
ast_from_value,
135137

136-
# A helper to use within recursive-descent visitors which need to be aware of
137-
# the GraphQL type system.
138-
TypeInfo,
138+
# A helper to use within recursive-descent visitors which need to be aware of
139+
# the GraphQL type system.
140+
TypeInfo,
139141

140-
# Determine if JavaScript values adhere to a GraphQL type.
141-
is_valid_value,
142+
# Determine if JavaScript values adhere to a GraphQL type.
143+
is_valid_value,
142144

143-
# Determine if AST values adhere to a GraphQL type.
144-
is_valid_literal_value,
145+
# Determine if AST values adhere to a GraphQL type.
146+
is_valid_literal_value,
145147

146-
# Concatenates multiple AST together.
147-
concat_ast,
148+
# Concatenates multiple AST together.
149+
concat_ast,
148150

149-
# Comparators for types
150-
is_equal_type,
151-
is_type_sub_type_of,
152-
do_types_overlap,
151+
# Comparators for types
152+
is_equal_type,
153+
is_type_sub_type_of,
154+
do_types_overlap,
153155

154-
# Asserts a string is a valid GraphQL name.
155-
assert_valid_name,
156+
# Asserts a string is a valid GraphQL name.
157+
assert_valid_name,
156158
)
157159

158160
__all__ = (
@@ -166,6 +168,8 @@
166168
'GraphQLInterfaceType',
167169
'GraphQLList',
168170
'GraphQLNonNull',
171+
'GraphQLField',
172+
'GraphQLArgument',
169173
'GraphQLObjectType',
170174
'GraphQLScalarType',
171175
'GraphQLSchema',

0 commit comments

Comments
 (0)