graphql-python / graphql-python/graphene-pydantic

how to pass in a json data struct?

Open
#101 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
249
Forks
47
PR merge metrics
No merged PRs in 30d

Description

I have the following challenge:

I am getting data from a database in json format / as dict.
This works great when I am directly grabbing the data in the query and "upgrading" it to the defined and in meta class registered pedantic data model.

Example:
```python
class GrapheneModel(PydanticObjectType):
class Meta:
model = PydanticModel

...
class Queries(ObjectType):
examples = List(
GrapheneModel
)

@staticmethod
def resolve_examples(root, info, **kwargs):
result = fetch_from_db() # return a list of dicts
return [PydanticModel.model_validate(q) for q in result]
```

But I also have other cases where I come through an interface.
I can overlay the is_type_of method to get to the right `GrapheneModel`, but the data that comes in is then a dict, which does not work... Do you guys have an idea how the data can be upgraded within the Graphene Model?
I cannot do it in the interface as I do not know the type there...
Thanks for any advise.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.