Skip to content

Commit

Permalink
feat: Added type conversion when using @requires
Browse files Browse the repository at this point in the history
  • Loading branch information
mak626 committed Mar 22, 2024
1 parent 99904a6 commit 06c5e1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 5 additions & 3 deletions examples/inaccessible.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import graphene

from graphene_federation import (
LATEST_VERSION, inaccessible,
LATEST_VERSION,
inaccessible,
external,
provides,
key,
override,
shareable,
)

from graphene_federation import build_schema
Expand Down Expand Up @@ -64,7 +64,9 @@ class Query(graphene.ObjectType):


schema = build_schema(
Query, federation_version=LATEST_VERSION, types=(ReviewInterface, SearchResult, Review)
Query,
federation_version=LATEST_VERSION,
types=(ReviewInterface, SearchResult, Review),
)

query = """
Expand Down
7 changes: 3 additions & 4 deletions examples/override.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import graphene

from graphene_federation import (
LATEST_VERSION, build_schema,
shareable,
external,
LATEST_VERSION,
build_schema,
inaccessible,
key,
override,
inaccessible,
)


Expand Down
8 changes: 7 additions & 1 deletion graphene_federation/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any
from typing import Dict, Type

from graphene import Field, List, NonNull, ObjectType, Union
from graphene import Enum, Field, List, NonNull, ObjectType, Scalar, Union
from graphene.types.schema import TypeMap
from graphene_directives import Schema
from graphene_directives.utils import has_non_field_attribute
Expand Down Expand Up @@ -123,6 +123,12 @@ def resolve_entities(self, info, representations, sub_field_resolution=False):
model_arguments[model_field] = EntityQuery.resolve_entities(
self, info, representations=value, sub_field_resolution=True
)
elif isinstance(field, Scalar) and getattr(
field, "parse_value", None
):
model_arguments[model_field] = field.parse_value(value)
elif isinstance(field, Enum):
model_arguments[model_field] = field._meta.enum[value] # noqa

model_instance = model(**model_arguments)

Expand Down

0 comments on commit 06c5e1e

Please sign in to comment.