Skip to content

Commit

Permalink
Merge branch 'mirumee:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
danplischke authored Dec 12, 2024
2 parents fc49301 + 0f68a08 commit eeea4f1
Show file tree
Hide file tree
Showing 26 changed files with 2,501 additions and 1,224 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ignore=snapshots
load-plugins=pylint.extensions.bad_builtin, pylint.extensions.mccabe

[MESSAGES CONTROL]
disable=C0103, C0111, C0209, C0412, I0011, R0101, R0801, R0901, R0902, R0903, R0912, R0913, R0914, R0915, R1260, W0105, W0231, W0511, W0621, W0703
disable=C0103, C0111, C0209, C0412, I0011, R0101, R0801, R0901, R0902, R0903, R0912, R0913, R0914, R0915, R0917, R1260, W0105, W0231, W0511, W0621, W0703

[SIMILARITIES]
ignore-imports=yes
76 changes: 38 additions & 38 deletions ariadne/contrib/federation/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# pylint: disable=cell-var-from-loop

import re
from inspect import isawaitable
from typing import Any, List
from typing import Any, List, Tuple, cast

from graphql import (
DirectiveDefinitionNode,
Node,
parse,
print_ast,
)
from graphql.language import DirectiveNode
from graphql.type import (
GraphQLNamedType,
Expand All @@ -14,36 +19,6 @@
)


_i_token_delimiter = r"(?:^|[\s]+|$)"
_i_token_name = "[_A-Za-z][_0-9A-Za-z]*"
_i_token_arguments = r"\([^)]*\)"
_i_token_location = "[_A-Za-z][_0-9A-Za-z]*"
_i_token_description_block_string = r"(?:\"{3}(?:[^\"]{1,}|[\s])\"{3})"
_i_token_description_single_line = r"(?:\"(?:[^\"\n\r])*?\")"

_r_directive_definition = re.compile(
"("
f"(?:{_i_token_delimiter}(?:"
f"{_i_token_description_block_string}|{_i_token_description_single_line}"
"))??"
f"{_i_token_delimiter}directive"
f"(?:{_i_token_delimiter})?@({_i_token_name})"
f"(?:(?:{_i_token_delimiter})?{_i_token_arguments})?"
f"{_i_token_delimiter}on"
f"{_i_token_delimiter}(?:[|]{_i_token_delimiter})?{_i_token_location}"
f"(?:{_i_token_delimiter}[|]{_i_token_delimiter}{_i_token_location})*"
")"
f"(?={_i_token_delimiter})",
)

_r_directive = re.compile(
"("
f"(?:{_i_token_delimiter})?@({_i_token_name})"
f"(?:(?:{_i_token_delimiter})?{_i_token_arguments})?"
")"
f"(?={_i_token_delimiter})",
)

_allowed_directives = [
"skip", # Default directive as per specs.
"include", # Default directive as per specs.
Expand All @@ -66,14 +41,39 @@
]


def _purge_directive_nodes(nodes: Tuple[Node, ...]) -> Tuple[Node, ...]:
return tuple(
node
for node in nodes
if not isinstance(node, (DirectiveNode, DirectiveDefinitionNode))
or node.name.value in _allowed_directives
)


def _purge_type_directives(definition: Node):
# Recursively check every field defined on the Node definition
# and remove any directives found.
for key in definition.keys:
value = getattr(definition, key, None)
if isinstance(value, tuple):
# Remove directive nodes from the tuple
# e.g. doc -> definitions [DirectiveDefinitionNode]
next_value = _purge_directive_nodes(cast(Tuple[Node, ...], value))
for item in next_value:
if isinstance(item, Node):
# Look for directive nodes on sub-nodes
# e.g. doc -> definitions [ObjectTypeDefinitionNode] -> fields -> directives
_purge_type_directives(item)
setattr(definition, key, next_value)
elif isinstance(value, Node):
_purge_type_directives(value)


def purge_schema_directives(joined_type_defs: str) -> str:
"""Remove custom schema directives from federation."""
joined_type_defs = _r_directive_definition.sub("", joined_type_defs)
joined_type_defs = _r_directive.sub(
lambda m: m.group(1) if m.group(2) in _allowed_directives else "",
joined_type_defs,
)
return joined_type_defs
ast_document = parse(joined_type_defs)
_purge_type_directives(ast_document)
return print_ast(ast_document)


def resolve_entities(_: Any, info: GraphQLResolveInfo, **kwargs) -> Any:
Expand Down
4 changes: 4 additions & 0 deletions ariadne/contrib/tracing/copy_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ def copy_args_for_tracing(value: Any) -> Any:


def repr_upload_file(upload_file: Union[UploadFile, File]) -> str:
filename: Union[str, None, bytes]
if isinstance(upload_file, File):
filename = upload_file.file_name
else:
filename = upload_file.filename

if isinstance(filename, bytes):
filename = filename.decode()

mime_type: Union[str, None]

if isinstance(upload_file, File):
Expand Down
4 changes: 4 additions & 0 deletions ariadne/contrib/tracing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ def copy_args_for_tracing(value: Any) -> Any:


def repr_upload_file(upload_file: Union[UploadFile, File]) -> str:
filename: Union[str, None, bytes]
if isinstance(upload_file, File):
filename = upload_file.file_name
else:
filename = upload_file.filename

if isinstance(filename, bytes):
filename = filename.decode()

mime_type: Union[str, None]

if isinstance(upload_file, File):
Expand Down
3 changes: 2 additions & 1 deletion ariadne/load_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from typing import Generator, Union

from graphql import parse
Expand Down Expand Up @@ -27,7 +28,7 @@ def load_schema_from_path(path: Union[str, os.PathLike]) -> str:
if os.path.isdir(path):
schema_list = [read_graphql_file(f) for f in sorted(walk_graphql_files(path))]
return "\n".join(schema_list)
return read_graphql_file(os.path.abspath(path))
return read_graphql_file(Path(path).resolve())


def walk_graphql_files(path: Union[str, os.PathLike]) -> Generator[str, None, None]:
Expand Down
7 changes: 5 additions & 2 deletions ariadne/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from multipart import parse_form
except ImportError:

def parse_form(*_args, **_kwargs):
def parse_form(*_args, **_kwargs): # type: ignore
raise NotImplementedError(
"WSGI file uploads requires 'python-multipart' library."
)
Expand Down Expand Up @@ -668,8 +668,11 @@ def parse_multipart_request(environ: dict) -> "FormData":
headers = {"Content-Type": content_type}
form_data = FormData(content_type)

# Silence mypy error for this incorrect type.
# parse_fprm defines the type as dict[str, bytes] but works with
# dict[str, Optional[str | bytes]] and will throw ValueError if Content-Type is None.
parse_form(
headers,
headers, # type: ignore
environ["wsgi.input"],
form_data.on_field,
form_data.on_file,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"machine_info": {
"node": "fv-az1424-240",
"node": "fv-az1121-475",
"processor": "x86_64",
"machine": "x86_64",
"python_compiler": "GCC 11.4.0",
"python_implementation": "CPython",
"python_implementation_version": "3.11.6",
"python_version": "3.11.6",
"python_implementation_version": "3.10.15",
"python_version": "3.10.15",
"python_build": [
"main",
"Oct 3 2023 04:42:57"
"Sep 9 2024 03:02:45"
],
"release": "6.2.0-1015-azure",
"release": "6.5.0-1025-azure",
"system": "Linux",
"cpu": {
"python_version": "3.11.6.final.0 (64 bit)",
"python_version": "3.10.15.final.0 (64 bit)",
"cpuinfo_version": [
9,
0,
Expand All @@ -27,14 +27,14 @@
"arch_string_raw": "x86_64",
"vendor_id_raw": "AuthenticAMD",
"brand_raw": "AMD EPYC 7763 64-Core Processor",
"hz_advertised_friendly": "3.2412 GHz",
"hz_actual_friendly": "3.2412 GHz",
"hz_advertised_friendly": "3.2428 GHz",
"hz_actual_friendly": "3.2428 GHz",
"hz_advertised": [
3241178000,
3242818000,
0
],
"hz_actual": [
3241178000,
3242818000,
0
],
"stepping": 1,
Expand Down Expand Up @@ -156,12 +156,12 @@
}
},
"commit_info": {
"id": "4c82e886a8f59717b09273e0bfd5178743731de1",
"time": "2023-11-07T15:00:50+00:00",
"author_time": "2023-11-07T15:00:50+00:00",
"id": "4a1d80732930742ad09a3c193c308ce202a4166e",
"time": "2024-11-19T16:48:21Z",
"author_time": "2024-11-19T16:48:21Z",
"dirty": false,
"project": "ariadne",
"branch": "master"
"branch": "main"
},
"benchmarks": [
{
Expand All @@ -180,22 +180,22 @@
"warmup": false
},
"stats": {
"min": 0.8520354650000002,
"max": 0.9228036680000002,
"mean": 0.8849478921999946,
"stddev": 0.027973199137541486,
"min": 1.002802398,
"max": 1.068786767000006,
"mean": 1.0350631961999994,
"stddev": 0.028191470636414688,
"rounds": 5,
"median": 0.8748913169999923,
"iqr": 0.0413973809999888,
"q1": 0.8667845802499983,
"q3": 0.9081819612499871,
"median": 1.0311538679999899,
"iqr": 0.049746089749991285,
"q1": 1.0112904562500056,
"q3": 1.0610365459999969,
"iqr_outliers": 0,
"stddev_outliers": 2,
"outliers": "2;0",
"ld15iqr": 0.8520354650000002,
"hd15iqr": 0.9228036680000002,
"ops": 1.1300100365389696,
"total": 4.424739460999973,
"ld15iqr": 1.002802398,
"hd15iqr": 1.068786767000006,
"ops": 0.9661245841522276,
"total": 5.175315980999997,
"iterations": 1
}
},
Expand All @@ -215,22 +215,22 @@
"warmup": false
},
"stats": {
"min": 0.875160477999998,
"max": 0.9448711500000115,
"mean": 0.9167900558000042,
"stddev": 0.02658106723801593,
"min": 1.0358900539999922,
"max": 1.084838406000003,
"mean": 1.0612142256000028,
"stddev": 0.017624453847653675,
"rounds": 5,
"median": 0.9150456819999988,
"iqr": 0.03184111325000316,
"q1": 0.9049107602500044,
"q3": 0.9367518735000075,
"median": 1.062145614000002,
"iqr": 0.019103342500002896,
"q1": 1.051738281500004,
"q3": 1.070841624000007,
"iqr_outliers": 0,
"stddev_outliers": 2,
"outliers": "2;0",
"ld15iqr": 0.875160477999998,
"hd15iqr": 0.9448711500000115,
"ops": 1.0907622674063426,
"total": 4.583950279000021,
"ld15iqr": 1.0358900539999922,
"hd15iqr": 1.084838406000003,
"ops": 0.9423168064248361,
"total": 5.3060711280000135,
"iterations": 1
}
},
Expand All @@ -250,22 +250,22 @@
"warmup": false
},
"stats": {
"min": 1.0439091610000162,
"max": 1.0776377809999929,
"mean": 1.0605849266000007,
"stddev": 0.012763915202105024,
"min": 1.229691953999989,
"max": 1.2955501099999935,
"mean": 1.2652441387999942,
"stddev": 0.025242474700776868,
"rounds": 5,
"median": 1.058578238999985,
"iqr": 0.017765634999982183,
"q1": 1.0523603447500136,
"q3": 1.0701259797499958,
"median": 1.2675904849999995,
"iqr": 0.0364941852500138,
"q1": 1.247428719749987,
"q3": 1.2839229050000007,
"iqr_outliers": 0,
"stddev_outliers": 2,
"outliers": "2;0",
"ld15iqr": 1.0439091610000162,
"hd15iqr": 1.0776377809999929,
"ops": 0.9428759309316016,
"total": 5.3029246330000035,
"ld15iqr": 1.229691953999989,
"hd15iqr": 1.2955501099999935,
"ops": 0.7903612981352659,
"total": 6.3262206939999714,
"iterations": 1
}
},
Expand All @@ -285,26 +285,26 @@
"warmup": false
},
"stats": {
"min": 0.9827471150000235,
"max": 1.0123632289999875,
"mean": 1.0012123502000065,
"stddev": 0.011538693531547845,
"min": 1.1233835339999985,
"max": 1.1743345209999916,
"mean": 1.1555877925999964,
"stddev": 0.020450022462859867,
"rounds": 5,
"median": 1.0046366109999951,
"iqr": 0.014749955999988629,
"q1": 0.994381863500017,
"q3": 1.0091318195000056,
"median": 1.1618279970000032,
"iqr": 0.028443919000004314,
"q1": 1.1423901389999926,
"q3": 1.170834057999997,
"iqr_outliers": 0,
"stddev_outliers": 1,
"outliers": "1;0",
"ld15iqr": 0.9827471150000235,
"hd15iqr": 1.0123632289999875,
"ops": 0.9987891178132547,
"total": 5.006061751000033,
"ld15iqr": 1.1233835339999985,
"hd15iqr": 1.1743345209999916,
"ops": 0.865360474040718,
"total": 5.777938962999983,
"iterations": 1
}
}
],
"datetime": "2023-11-07T15:01:53.671730",
"version": "4.0.0"
"datetime": "2024-11-19T16:49:17.407693+00:00",
"version": "5.1.0"
}
Loading

0 comments on commit eeea4f1

Please sign in to comment.