Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

how to pass in a json data struct? #101

Copy link
Copy link
Open
@c-xlenz

Description

@c-xlenz
Issue body actions

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.