Skip to content

Commit d891622

Browse files
committed
Added new model class without relay
1 parent 00d8b22 commit d891622

File tree

5 files changed

+78
-7
lines changed

5 files changed

+78
-7
lines changed

examples/django_mongoengine/bike/fixtures.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import pytest
2-
from .models import Bike
2+
from .models import Bike, Shop
33

44

5-
@pytest.fixture(scope='module')
6-
def fixtures_data():
5+
def fixture_bike_data():
76
Bike.drop_collection()
87
bike_one = Bike(
98
name='Level R',
@@ -25,4 +24,26 @@ def fixtures_data():
2524
)
2625
bike_two.save()
2726

27+
28+
def fixture_shop_data():
29+
Shop.drop_collection()
30+
shop_one = Shop(
31+
name="Big Wheel Bicycles",
32+
address="2438 Hart Ridge Road",
33+
website="https://www.bigwheelbike.test"
34+
)
35+
shop_one.save()
36+
shop_two = Shop(
37+
name="Bike Tech",
38+
address="2175 Pearl Street",
39+
website="https://www.biketech.test"
40+
)
41+
shop_two.save()
42+
43+
44+
@pytest.fixture(scope='module')
45+
def fixtures_data():
46+
fixture_bike_data()
47+
fixture_shop_data()
48+
2849
return True

examples/django_mongoengine/bike/models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
from mongoengine import Document
2-
from mongoengine.fields import FloatField, StringField, ListField
2+
from mongoengine.fields import FloatField, StringField, ListField, URLField
3+
4+
5+
class Shop(Document):
6+
meta = {'collection': 'shop'}
7+
name = StringField()
8+
address = StringField()
9+
website = URLField()
310

411

512
class Bike(Document):
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import graphene
22
from graphene.relay import Node
33
from graphene_mongo.fields import MongoengineConnectionField
4-
from .types import BikeType
4+
from .models import Shop
5+
from .types import BikeType, ShopType
56

67

78
class Query(graphene.ObjectType):
89
node = Node.Field()
910
bikes = MongoengineConnectionField(BikeType)
11+
shop_list = graphene.List(ShopType)
12+
13+
def resolve_shop_list(self, info):
14+
return Shop.objects.all()
1015

1116

1217
schema = graphene.Schema(query=Query, types=[BikeType, ])

examples/django_mongoengine/bike/tests.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_bikes_filter_by_type_item_query(fixtures_data):
7676
"wheelSize": 27.5,
7777
"type": "MTB"
7878
}
79-
},
79+
}
8080
]
8181
}
8282
}
@@ -85,3 +85,36 @@ def test_bikes_filter_by_type_item_query(fixtures_data):
8585
client = Client(schema)
8686
result = client.execute(query)
8787
assert result == expected
88+
89+
90+
def test_shop_data_query(fixtures_data):
91+
query = '''{
92+
shopList{
93+
name
94+
address
95+
website
96+
}
97+
}'''
98+
99+
expected = {
100+
"data": {
101+
"shopList": [
102+
{
103+
104+
"name": "Big Wheel Bicycles",
105+
"address": "2438 Hart Ridge Road",
106+
"website": "https://www.bigwheelbike.test",
107+
108+
},
109+
{
110+
"name": "Bike Tech",
111+
"address": "2175 Pearl Street",
112+
"website": "https://www.biketech.test",
113+
}
114+
]
115+
}
116+
}
117+
118+
client = Client(schema)
119+
result = client.execute(query)
120+
assert result == expected
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
from graphene import relay
22
from graphene_mongo import MongoengineObjectType
3-
from .models import Bike
3+
from .models import Bike, Shop
44

55

66
class BikeType(MongoengineObjectType):
77
class Meta:
88
model = Bike
99
interfaces = (relay.Node,)
10+
11+
12+
class ShopType(MongoengineObjectType):
13+
class Meta:
14+
model = Shop

0 commit comments

Comments
 (0)