{"id":6659,"library":"graphene-pydantic","title":"Graphene Pydantic Integration","description":"A Pydantic integration for Graphene, currently at version 0.6.1. It provides utilities to automatically convert Pydantic `BaseModel`s into Graphene `ObjectType`s and `InputObjectType`s, streamlining GraphQL schema generation. The library sees active development with updates addressing Pydantic and Graphene version compatibility.","status":"active","version":"0.6.1","language":"en","source_language":"en","source_url":"https://github.com/graphql-python/graphene-pydantic","tags":["graphene","pydantic","graphql","schema-generation","api"],"install":[{"cmd":"pip install \"graphene-pydantic\"","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for GraphQL schema definition.","package":"graphene","optional":false},{"reason":"Core dependency for data model definition.","package":"pydantic","optional":false}],"imports":[{"symbol":"PydanticObjectType","correct":"from graphene_pydantic import PydanticObjectType"},{"symbol":"PydanticInputObjectType","correct":"from graphene_pydantic import PydanticInputObjectType"}],"quickstart":{"code":"import uuid\nimport pydantic\nimport graphene\nfrom graphene_pydantic import PydanticObjectType\n\nclass PersonModel(pydantic.BaseModel):\n    id: uuid.UUID\n    first_name: str\n    last_name: str\n\nclass Person(PydanticObjectType):\n    class Meta:\n        model = PersonModel\n        exclude_fields = (\"id\",)\n\nclass Query(graphene.ObjectType):\n    people = graphene.List(Person)\n\n    @staticmethod\n    def resolve_people(parent, info):\n        # In a real application, you would fetch data from a database\n        return [\n            PersonModel(id=uuid.uuid4(), first_name=\"Alice\", last_name=\"Smith\"),\n            PersonModel(id=uuid.uuid4(), first_name=\"Bob\", last_name=\"Johnson\")\n        ]\n\nschema = graphene.Schema(query=Query)\n\nquery = \"\"\"\nquery {\n  people {\n    firstName,\n    lastName\n  }\n}\n\"\"\"\n\nresult = schema.execute(query)\nprint(result.data['people'])\n# Expected output: [{'firstName': 'Alice', 'lastName': 'Smith'}, {'firstName': 'Bob', 'lastName': 'Johnson'}]","lang":"python","description":"This quickstart demonstrates how to define a Pydantic model and automatically convert it into a Graphene `ObjectType` using `PydanticObjectType`. It then sets up a basic GraphQL schema and executes a sample query."},"warnings":[{"fix":"Upgrade Python to 3.7+ and Pydantic to 1.7+ before upgrading graphene-pydantic to 0.3.0 or later.","message":"Version 0.3.0 dropped support for Python 3.6 and Pydantic versions older than 1.7. Ensure your environment meets these minimum requirements.","severity":"breaking","affected_versions":"0.3.0 and later"},{"fix":"Upgrade Pydantic to a 1.x version first, addressing any Pydantic-specific breaking changes, then upgrade graphene-pydantic.","message":"Version 0.1.0 removed support for Pydantic 0.x. If migrating from very old Pydantic versions, significant changes may be required.","severity":"breaking","affected_versions":"0.1.0 and later"},{"fix":"Represent dictionary fields as `JSONString` or define custom scalar types/Graphene `ObjectType`s for complex mapping structures, and provide custom resolvers.","message":"Due to a GraphQL limitation, Pydantic fields that hold mappings (e.g., dictionaries) cannot be directly exported to Graphene types.","severity":"gotcha","affected_versions":"All"},{"fix":"Avoid `Union` types in `PydanticInputObjectType` fields. Consider using separate input types for each union member or redesigning the input structure.","message":"GraphQL Input Object Types do not support unions as fields. Attempting to use a Pydantic `Union` type in an `PydanticInputObjectType` will lead to errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Implement `is_type_of` in Graphene models representing union members. For `Union[Subclass, Baseclass]`, define as `Union[Subclass, Baseclass]`.","message":"When using `Union` types in `PydanticObjectType`, you must explicitly implement the `is_type_of` class method in your Graphene models. For unions between subclasses, the subclass must be listed first in the type annotation to ensure correct resolution.","severity":"gotcha","affected_versions":"All"},{"fix":"Refer to Pydantic's official migration guide for V1 to V2 changes. Use Pydantic's `bump-pydantic` tool for automated code transformation where possible. Thoroughly test your Graphene schema after Pydantic model updates.","message":"The library supports Pydantic versions `~1.7` through `~2.x`. However, Pydantic itself introduced significant breaking changes between V1 and V2. While `graphene-pydantic` aims to be compatible, migrating your underlying Pydantic models from V1 to V2 may still require substantial refactoring.","severity":"gotcha","affected_versions":"All (especially when migrating Pydantic versions)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}