Skip to content

Commit 13b55d9

Browse files
committed
Merge pull request #51 from graphql-python/releases/0.4.14
Way to 0.4.14
2 parents cab838c + 027c405 commit 13b55d9

35 files changed

+632
-86
lines changed

graphql/core/language/visitor.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55
from . import ast
66
from .visitor_meta import QUERY_DOCUMENT_KEYS, VisitorMeta
77

8+
9+
class Falsey(object):
10+
def __nonzero__(self):
11+
return False
12+
13+
def __bool__(self):
14+
return False
15+
16+
817
BREAK = object()
9-
REMOVE = object()
18+
REMOVE = Falsey()
1019

1120

1221
class Stack(object):
@@ -90,7 +99,7 @@ def visit(root, visitor, key_map=None):
9099
key = None
91100
node = new_root
92101

93-
if node is None:
102+
if node is REMOVE or node is None:
94103
continue
95104

96105
if parent:
@@ -162,3 +171,55 @@ def leave(self, node, key, parent, path, ancestors):
162171
method = self._get_leave_handler(type(node))
163172
if method:
164173
return method(self, node, key, parent, path, ancestors)
174+
175+
176+
class ParallelVisitor(Visitor):
177+
__slots__ = 'skipping', 'visitors'
178+
179+
def __init__(self, visitors):
180+
self.visitors = visitors
181+
self.skipping = [None] * len(visitors)
182+
183+
def enter(self, node, key, parent, path, ancestors):
184+
for i, visitor in enumerate(self.visitors):
185+
if not self.skipping[i]:
186+
result = visitor.enter(node, key, parent, path, ancestors)
187+
if result is False:
188+
self.skipping[i] = node
189+
elif result is BREAK:
190+
self.skipping[i] = BREAK
191+
elif result is not None:
192+
return result
193+
194+
def leave(self, node, key, parent, path, ancestors):
195+
for i, visitor in enumerate(self.visitors):
196+
if not self.skipping[i]:
197+
result = visitor.leave(node, key, parent, path, ancestors)
198+
if result is BREAK:
199+
self.skipping[i] = BREAK
200+
elif result is not None and result is not False:
201+
return result
202+
elif self.skipping[i] == node:
203+
self.skipping[i] = REMOVE
204+
205+
206+
class TypeInfoVisitor(Visitor):
207+
__slots__ = 'visitor', 'type_info'
208+
209+
def __init__(self, type_info, visitor):
210+
self.type_info = type_info
211+
self.visitor = visitor
212+
213+
def enter(self, node, key, parent, path, ancestors):
214+
self.type_info.enter(node)
215+
result = self.visitor.enter(node, key, parent, path, ancestors)
216+
if result is not None:
217+
self.type_info.leave(node)
218+
if isinstance(result, ast.Node):
219+
self.type_info.enter(result)
220+
return result
221+
222+
def leave(self, node, key, parent, path, ancestors):
223+
result = self.visitor.leave(node, key, parent, path, ancestors)
224+
self.type_info.leave(node)
225+
return result

graphql/core/type/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
GraphQLInputObjectField,
1313
GraphQLList,
1414
GraphQLNonNull,
15+
get_named_type,
1516
is_abstract_type,
1617
is_composite_type,
1718
is_input_type,

graphql/core/type/scalars.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from ..language.ast import BooleanValue, FloatValue, IntValue, StringValue
44
from .definition import GraphQLScalarType
55

6-
# Integers are only safe when between -(2^53 - 1) and 2^53 - 1 due to being
7-
# encoded in JavaScript and represented in JSON as double-precision floating
8-
# point numbers, as specified by IEEE 754.
9-
MAX_INT = 9007199254740991
10-
MIN_INT = -9007199254740991
6+
# As per the GraphQL Spec, Integers are only treated as valid when a valid
7+
# 32-bit signed integer, providing the broadest support across platforms.
8+
#
9+
# n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because
10+
# they are internally represented as IEEE 754 doubles.
11+
MAX_INT = 2147483647
12+
MIN_INT = -2147483648
1113

1214

1315
def coerce_int(value):

graphql/core/validation/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from ..language.visitor import visit
1+
from ..language.visitor import ParallelVisitor, TypeInfoVisitor, visit
22
from ..type import GraphQLSchema
33
from ..utils.type_info import TypeInfo
44
from .context import ValidationContext
55
from .rules import specified_rules
6-
from .visitor import ParallelVisitor, TypeInfoVisitor
76

87

98
def validate(schema, ast, rules=specified_rules):

graphql/core/validation/context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from ..language.ast import (FragmentDefinition, FragmentSpread,
22
OperationDefinition)
3-
from ..language.visitor import Visitor, visit
4-
from .visitor import TypeInfoVisitor
3+
from ..language.visitor import TypeInfoVisitor, Visitor, visit
54

65

76
class VariableUsage(object):

graphql/core/validation/rules/known_type_names.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
class KnownTypeNames(ValidationRule):
66

7+
def enter_ObjectTypeDefinition(self, node, *args):
8+
return False
9+
10+
def enter_InterfaceTypeDefinition(self, node, *args):
11+
return False
12+
13+
def enter_UnionTypeDefinition(self, node, *args):
14+
return False
15+
16+
def enter_InputObjectTypeDefinition(self, node, *args):
17+
return False
18+
719
def enter_NamedType(self, node, *args):
820
type_name = node.name.value
921
type = self.context.get_schema().get_type(type_name)

graphql/core/validation/visitor.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)