Skip to content

Commit 2fd67a8

Browse files
authored
Merge pull request #71 from conglei/conglei-make-it-graphene-2-compatiable
Make it graphene 2 compatible
2 parents d4df6af + ebbd064 commit 2fd67a8

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

graphene_pydantic/converters.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ def convert_pydantic_field(
131131
# - maybe even (Sphinx-style) parse attribute documentation
132132
field_kwargs.setdefault("description", field.field_info.description)
133133

134-
# Somehow, this happens
135-
if "type_" not in field_kwargs and "type" in field_kwargs:
136-
field_kwargs["type_"] = field_kwargs.pop("type")
134+
# Handle Graphene 2 and 3
135+
field_type = field_kwargs.pop("type", field_kwargs.pop("type_", None))
136+
if field_type is None:
137+
raise ValueError("No field type could be determined.")
137138

138-
return Field(resolver=get_attr_resolver(field.name), **field_kwargs)
139+
return Field(field_type, resolver=get_attr_resolver(field.name), **field_kwargs)
139140

140141

141142
def convert_pydantic_type(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ keywords = ["api", "graphql", "protocol", "rest", "relay", "graphene", "pydantic
2424
[tool.poetry.dependencies]
2525
python = "^3.7"
2626
# To keep things simple, we only support newer versions of Graphene & Pydantic
27-
graphene = "~=3.0"
27+
graphene = ">=2.1.8"
2828
pydantic = [
2929
{ version = ">=1.0,<2.0", python = ">3.6,<3.10" },
3030
{ version = ">=1.9,<2.0", python = "~3.10" }

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# https://tox.readthedocs.io/en/latest/example/basic.html#compressing-dependency-matrix
22
[tox]
33
# NOTE: Pydantic <1.9 does not support Python 3.10
4-
envlist = py{37,38,39}-graphene{30}-pydantic{17,18,19}, py310-graphene30-pydantic19
4+
envlist = py{37,38,39}-graphene{21,30}-pydantic{17,18,19}, py310-graphene30-pydantic19
55
# CI will supply any versions not available locally
66
skip_missing_interpreters = True
77
# required if working with pyproject.toml
@@ -12,6 +12,7 @@ requires =
1212
[testenv]
1313
whitelist_externals = poetry
1414
deps =
15+
graphene21: graphene>=2.1.8
1516
graphene30: graphene>=3.0,<3.1
1617
pydantic17: pydantic==1.7
1718
pydantic18: pydantic==1.8

0 commit comments

Comments
 (0)