Skip to content

Support type hinting for InputObjectTypes #49

@alex-grover

Description

@alex-grover

Take the following example, adapted from the README:

import uuid

import graphene
import pydantic
from graphene_pydantic import PydanticInputObjectType, PydanticObjectType


class PersonModel(pydantic.BaseModel):
    id: uuid.UUID
    first_name: str
    last_name: str


class PersonInput(PydanticInputObjectType):
    class Meta:
        model = PersonModel
        exclude_fields = ("id",)


class CreatePerson(graphene.Mutation):
    class Arguments:
        person = PersonInput()

    @staticmethod
    def mutate(parent, info, person: PersonInput):  # I'd like to type hint this argument
        personModel = PersonModel(
            id=uuid.uuid4(),
            first_name=person.first_name,
            last_name=person.last_name
        )
        return person

It would be nice to be able to type hint the model properties that are defined on the InputObjectType through introspection. Currently, the mutate method generates type warnings:

Screen Shot 2020-12-02 at 10 09 38 AM

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