Skip to content

Commit

Permalink
Merge pull request #117 from evo-company/add-deprecated-argument
Browse files Browse the repository at this point in the history
add deprecated argument to Field and Link
  • Loading branch information
kindermax committed Aug 10, 2023
2 parents 0ccd628 + 3c7a6f0 commit acf6847
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 11 deletions.
21 changes: 18 additions & 3 deletions docs/changelog/changes_07.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,31 @@ Changes in 0.7
directives=[Deprecated('use another field')]),
]),
])
Or you can use ``deprecated`` argument to :py:class:`hiku.graph.Field`: or :py:class:`hiku.graph.Link`:

.. code-block:: python
from hiku.directives import Deprecated
graph = Graph([
Root([
Field('lorem-ipsum', String, func,
options=[Option('words', Integer, default=50)],
deprecated='use another field'),
]),
])
- Added mypy and typings to codebase
- Added checks for unhashable link results and extend errors. This must improve developer experience.
- Added checks for link results that can not be hashed and extend errors. This must improve developer experience.
- Added caching for parsing graphql query. It is optional and can be enabled by calling :py:func:`hiku.readers.graphql.setup_query_cache`.
- Added result cache - it is possible now to specify ``@cached`` directive to cache parts of the query. :ref:`Check cache documentation <caching-doc>`
- ``Link(requires=['a', 'b'])`` can be specified as a list of strings. It is useful when you want to require multiple fields at once. It will pass a list of dicts to the resolver.
- Added support for Python 3.11
- Added hints when failing on unhashable return values
- Added hints when failing on return values that are not hashable
- Migrated to ``pdm`` package manager
- Reformat code with ``black``
- Added support for Apollo Federation v2
- Added support for Apollo Federation v2 (v2 is default now)
- Added support for custom schema directives :ref:`Check directives documentation <directives-doc>`
- Added `ID` type.
- Added support for unions :ref:`Check unions documentation <unions-doc>`
Expand Down
36 changes: 28 additions & 8 deletions hiku/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
const,
Const,
)
from .directives import SchemaDirective
from .directives import Deprecated, SchemaDirective

from .compat import TypeAlias

Expand Down Expand Up @@ -208,7 +208,8 @@ def __init__(
*,
options: t.Optional[t.Sequence[Option]] = None,
description: t.Optional[str] = None,
directives: t.Optional[t.Sequence[SchemaDirective]] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
"""
:param str name: name of the field
Expand All @@ -217,13 +218,20 @@ def __init__(
:param options: list of acceptable options
:param description: description of the field
:param directives: list of directives for the field
:param deprecated: deprecation reason
"""
if directives is None:
directives = []

if deprecated is not None:
directives.append(Deprecated(deprecated))

self.name = name
self.type = type_
self.func = func
self.options = options or ()
self.description = description
self.directives = directives or ()
self.directives = directives
self.type_info = get_field_type(type_)

def __repr__(self) -> str:
Expand Down Expand Up @@ -490,7 +498,8 @@ def __init__(
requires: t.Optional[t.Union[str, t.List[str]]],
options: t.Optional[t.Sequence[Option]] = None,
description: t.Optional[str] = None,
directives: t.Optional[t.Sequence[SchemaDirective]] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
...

Expand All @@ -504,7 +513,8 @@ def __init__(
requires: t.Optional[t.Union[str, t.List[str]]],
options: t.Optional[t.Sequence[Option]] = None,
description: t.Optional[str] = None,
directives: t.Optional[t.Sequence[SchemaDirective]] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
...

Expand All @@ -518,7 +528,8 @@ def __init__(
requires: t.Optional[t.Union[str, t.List[str]]],
options: t.Optional[t.Sequence[Option]] = None,
description: t.Optional[str] = None,
directives: t.Optional[t.Sequence[SchemaDirective]] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
...

Expand All @@ -532,7 +543,8 @@ def __init__(
requires: t.Optional[t.Union[str, t.List[str]]],
options: t.Optional[t.Sequence[Option]] = None,
description: t.Optional[str] = None,
directives: t.Optional[t.Sequence[SchemaDirective]] = None,
directives: t.Optional[t.List[SchemaDirective]] = None,
deprecated: t.Optional[str] = None,
):
...

Expand All @@ -546,6 +558,7 @@ def __init__( # type: ignore[no-untyped-def]
options=None,
description=None,
directives=None,
deprecated=None,
):
"""
:param name: name of the link
Expand All @@ -556,9 +569,16 @@ def __init__( # type: ignore[no-untyped-def]
:param options: list of acceptable options
:param description: description of the link
:param directives: list of directives for the link
:param deprecated: deprecation reason for the link
"""
type_enum, node = get_link_type_enum(type_)

if directives is None:
directives = []

if deprecated is not None:
directives.append(Deprecated(deprecated))

self.name = name
self.type = type_
self.type_enum = type_enum
Expand All @@ -567,7 +587,7 @@ def __init__( # type: ignore[no-untyped-def]
self.requires = requires
self.options = options or ()
self.description = description
self.directives = directives or ()
self.directives = directives
self.type_info = get_link_type(type_)

def __repr__(self) -> str:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_validate_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,27 @@ def test_field_uses_more_than_one_deprecated_directive():
['Deprecated directive must be used only once for "bar.id", found 2'],
)

def test_deprecated_directive_with_deprecated_argument():
check_errors(
[
Node(
"bar",
[
Field(
"id",
None,
_fields_func,
directives=[
Deprecated("do not use"),
],
deprecated="do not use 2",
),
],
),
],
['Deprecated directive must be used only once for "bar.id", found 2'],
)


def test_link_uses_more_than_one_deprecated_directive():
check_errors(
Expand Down

0 comments on commit acf6847

Please sign in to comment.