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

Differentiate between default value and unset value in InputObjectType #111

Copy link
Copy link
Open
@konnerthg

Description

@konnerthg
Issue body actions

given the type

class PersonInput(InputObjectType):
    name = Field(String, required=False)

and the mutation

class UpdatePersonMutation:

    class Arguments:
        person_data = PersonInput(required=True)

    def mutate(cls, root, info, person_data):
        print(person_data)

how do i differentiate whether the query set the name field to None, explicitly? or just left it empty? Both yield the same output. and i understand that this is due to the default value in the input object. the output is:

{
    "name": None,
}

GQL query with None by default:

update_person(
    person_data: {
    }
)

GQL query with explicit None:

update_person(
    person_data: {
         name: null
    }
)

The context of my attempt:
I'm writing a CRUD endpoint for a model, in this example it is Person. For the Update operation, I want the ability to delete a field (i.e. set it to None in the database). but also to leave it unmodified.
to delete, the update would be {"name": None} and to leave unmodified, the update would be {}.
note that i cannot send a exclude_none flag in the query, because the real query is much larger than my example, let's say

person_update_data = {
    "name": None,  # set "name" to None in the database
    "first_name": Eric,  # update this field in the database
    # no "last_name" field in the query, therefore do not modify "last_name" in the database
    # etc
}

What is the correct way to implement this in graphene?
pydantic models for example, have an exclude_unset option. but I cannot find this in the graphene InputObjectType.

Thank you

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.