mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-29 13:03:56 +03:00
Chore: Refactor Multi Expression Code
This commit is contained in:
parent
0a54094f59
commit
9e17044ddc
|
@ -19,10 +19,7 @@ def get_version(version=None):
|
||||||
sub = ""
|
sub = ""
|
||||||
if version[3] == "alpha" and version[4] == 0:
|
if version[3] == "alpha" and version[4] == 0:
|
||||||
git_changeset = get_git_changeset()
|
git_changeset = get_git_changeset()
|
||||||
if git_changeset:
|
sub = ".dev%s" % git_changeset if git_changeset else ".dev"
|
||||||
sub = ".dev%s" % git_changeset
|
|
||||||
else:
|
|
||||||
sub = ".dev"
|
|
||||||
elif version[3] != "final":
|
elif version[3] != "final":
|
||||||
mapping = {"alpha": "a", "beta": "b", "rc": "rc"}
|
mapping = {"alpha": "a", "beta": "b", "rc": "rc"}
|
||||||
sub = mapping[version[3]] + str(version[4])
|
sub = mapping[version[3]] + str(version[4])
|
||||||
|
|
|
@ -18,11 +18,7 @@ def is_node(objecttype):
|
||||||
if not issubclass(objecttype, ObjectType):
|
if not issubclass(objecttype, ObjectType):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for i in objecttype._meta.interfaces:
|
return any(issubclass(i, Node) for i in objecttype._meta.interfaces)
|
||||||
if issubclass(i, Node):
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class GlobalID(Field):
|
class GlobalID(Field):
|
||||||
|
@ -92,9 +88,7 @@ class Node(AbstractNode):
|
||||||
_type, _id = cls.from_global_id(global_id)
|
_type, _id = cls.from_global_id(global_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f'Unable to parse global ID "{global_id}". '
|
f'Unable to parse global ID "{global_id}". Make sure it is a base64 encoded string in the format: "TypeName:id". Exception message: {e}'
|
||||||
'Make sure it is a base64 encoded string in the format: "TypeName:id". '
|
|
||||||
f"Exception message: {str(e)}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
graphene_type = info.schema.get_type(_type)
|
graphene_type = info.schema.get_type(_type)
|
||||||
|
|
|
@ -101,10 +101,7 @@ class Mutation(ObjectType):
|
||||||
"Read more:"
|
"Read more:"
|
||||||
" https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#mutation-input"
|
" https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#mutation-input"
|
||||||
)
|
)
|
||||||
if input_class:
|
arguments = props(input_class) if input_class else {}
|
||||||
arguments = props(input_class)
|
|
||||||
else:
|
|
||||||
arguments = {}
|
|
||||||
if not resolver:
|
if not resolver:
|
||||||
mutate = getattr(cls, "mutate", None)
|
mutate = getattr(cls, "mutate", None)
|
||||||
assert mutate, "All mutations must define a mutate method in it"
|
assert mutate, "All mutations must define a mutate method in it"
|
||||||
|
|
|
@ -7,9 +7,7 @@ def dict_resolver(attname, default_value, root, info, **args):
|
||||||
|
|
||||||
|
|
||||||
def dict_or_attr_resolver(attname, default_value, root, info, **args):
|
def dict_or_attr_resolver(attname, default_value, root, info, **args):
|
||||||
resolver = attr_resolver
|
resolver = dict_resolver if isinstance(root, dict) else attr_resolver
|
||||||
if isinstance(root, dict):
|
|
||||||
resolver = dict_resolver
|
|
||||||
return resolver(attname, default_value, root, info, **args)
|
return resolver(attname, default_value, root, info, **args)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,7 @@ class Subscription(ObjectType):
|
||||||
count_to_ten = Field(Int)
|
count_to_ten = Field(Int)
|
||||||
|
|
||||||
async def subscribe_count_to_ten(root, info):
|
async def subscribe_count_to_ten(root, info):
|
||||||
count = 0
|
for count in range(1, 11):
|
||||||
while count < 10:
|
|
||||||
count += 1
|
|
||||||
yield count
|
yield count
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,19 +27,18 @@ def import_string(dotted_path, dotted_attributes=None):
|
||||||
|
|
||||||
if not dotted_attributes:
|
if not dotted_attributes:
|
||||||
return result
|
return result
|
||||||
else:
|
attributes = dotted_attributes.split(".")
|
||||||
attributes = dotted_attributes.split(".")
|
traveled_attributes = []
|
||||||
traveled_attributes = []
|
try:
|
||||||
try:
|
for attribute in attributes:
|
||||||
for attribute in attributes:
|
traveled_attributes.append(attribute)
|
||||||
traveled_attributes.append(attribute)
|
result = getattr(result, attribute)
|
||||||
result = getattr(result, attribute)
|
return result
|
||||||
return result
|
except AttributeError:
|
||||||
except AttributeError:
|
raise ImportError(
|
||||||
raise ImportError(
|
'Module "%s" does not define a "%s" attribute inside attribute/class "%s"'
|
||||||
'Module "%s" does not define a "%s" attribute inside attribute/class "%s"'
|
% (module_path, ".".join(traveled_attributes), class_name)
|
||||||
% (module_path, ".".join(traveled_attributes), class_name)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def lazy_import(dotted_path, dotted_attributes=None):
|
def lazy_import(dotted_path, dotted_attributes=None):
|
||||||
|
|
|
@ -38,4 +38,4 @@ def test_orderedtype_non_orderabletypes():
|
||||||
|
|
||||||
assert one.__lt__(1) == NotImplemented
|
assert one.__lt__(1) == NotImplemented
|
||||||
assert one.__gt__(1) == NotImplemented
|
assert one.__gt__(1) == NotImplemented
|
||||||
assert not one == 1
|
assert one != 1
|
||||||
|
|
|
@ -18,14 +18,12 @@ schema = Schema(query=Query)
|
||||||
def run_query(query: str):
|
def run_query(query: str):
|
||||||
document = parse(query)
|
document = parse(query)
|
||||||
|
|
||||||
errors = validate(
|
return validate(
|
||||||
schema=schema.graphql_schema,
|
schema=schema.graphql_schema,
|
||||||
document_ast=document,
|
document_ast=document,
|
||||||
rules=(DisableIntrospection,),
|
rules=(DisableIntrospection,),
|
||||||
)
|
)
|
||||||
|
|
||||||
return errors
|
|
||||||
|
|
||||||
|
|
||||||
def test_disallows_introspection_queries():
|
def test_disallows_introspection_queries():
|
||||||
errors = run_query("{ __schema { queryType { name } } }")
|
errors = run_query("{ __schema { queryType { name } } }")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user