Skip to content

Commit 96a1bb2

Browse files
committed
fix(Bson): Made BSON objectID optional support, removed from dependencies
1 parent 745ab32 commit 96a1bb2

File tree

3 files changed

+9
-45
lines changed

3 files changed

+9
-45
lines changed

graphene_pydantic/converters.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from types import UnionType
1111

1212
import graphene
13-
from bson import ObjectId
1413
from graphene import (Boolean, Enum, Field, Float, ID, InputField, Int, JSONString, List, String, UUID, Union)
1514
from graphene.types.base import BaseType
1615
from graphene.types.datetime import Date, DateTime, Time
@@ -23,6 +22,12 @@
2322

2423
GRAPHENE2 = graphene.VERSION[0] < 3
2524

25+
try:
26+
from bson import ObjectId
27+
BSON_OBJECT_ID_SUPPORTED = True
28+
except ImportError:
29+
BSON_OBJECT_ID_SUPPORTED = False
30+
2631
try:
2732
from graphene.types.decimal import Decimal as GrapheneDecimal
2833

@@ -177,7 +182,7 @@ def find_graphene_type(
177182
return Boolean
178183
elif type_ == float:
179184
return Float
180-
elif type_ == ObjectId:
185+
elif BSON_OBJECT_ID_SUPPORTED and type_ == ObjectId:
181186
return ID
182187
elif type_ == dict:
183188
return JSONString

poetry.lock

Lines changed: 1 addition & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@ classifiers = [
1313
"Development Status :: 3 - Alpha",
1414
"Intended Audience :: Developers",
1515
"Topic :: Software Development :: Libraries",
16-
"Programming Language :: Python :: 3.6",
17-
"Programming Language :: Python :: 3.7",
1816
"Programming Language :: Python :: 3.8",
1917
"Programming Language :: Python :: 3.9",
2018
"Programming Language :: Python :: 3.10",
2119
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
2221
"Programming Language :: Python :: Implementation :: PyPy",
2322
]
2423
keywords = ["api", "graphql", "protocol", "rest", "relay", "graphene", "pydantic", "model"]
2524

2625
[tool.poetry.dependencies]
2726
python = "^3.7"
2827
graphene = ">=2.1.8"
29-
bson = "^0.5.10"
3028
pydantic = ">=2.0"
3129

3230
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)