Skip to content

Commit

Permalink
bump: 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mak626 committed Jan 13, 2024
1 parent 5126ea3 commit e7efbdd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,25 @@ from graphql import (
from graphene_directives import CustomDirective, DirectiveLocation, ValidatorLocation, build_schema, directive_decorator


def validate_input(_type: Any, _location_type: ValidatorLocation, inputs: dict) -> bool:
def validate_non_field_input(_type: Any, inputs: dict) -> bool:
"""
def validator (type_: graphene type, inputs: Any) -> bool,
if validator returns False, library raises DirectiveCustomValidationError
"""
if inputs.get("max_age") > 2500:
return False
return True


def validate_field_input(_parent_type: Any, _field_type: Any, inputs: dict) -> bool:
"""
def validator (parent_type_: graphene_type, field_type_: graphene type, inputs: Any) -> bool,
if validator returns False, library raises DirectiveCustomValidationError
"""
if inputs.get("max_age") > 2500:
return False
return True

CacheDirective = CustomDirective(
name="cache",
locations=[DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.OBJECT],
Expand All @@ -176,7 +189,8 @@ CacheDirective = CustomDirective(
),
},
description="Caching directive to control cache behavior of fields or fragments.",
non_field_validator=validate_input,
non_field_validator=validate_non_field_input,
field_validator=validate_field_input,
)

# This returns a partial of directive function
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "graphene-directives"
version = "0.3.3"
version = "0.4.0"
packages = [{include = "graphene_directives"}]
description = "Schema Directives implementation for graphene"
authors = ["Strollby <developers@strollby.com>"]
Expand Down

0 comments on commit e7efbdd

Please sign in to comment.