Skip to content

Commit 439153b

Browse files
authored
Merge pull request #9 from graphql-python/test-custom-kwargs
Test first n and custom kwargs
2 parents e5b0d82 + a385e22 commit 439153b

File tree

5 files changed

+99
-16
lines changed

5 files changed

+99
-16
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A [Mongoengine](https://mongoengine-odm.readthedocs.io/) integration for [Graphe
77

88
## Installation
99

10-
For instaling graphene, just run this command in your shell
10+
For instaling graphene-mongo, just run this command in your shell
1111

1212
```
1313
pip install graphene-mongo
@@ -63,17 +63,22 @@ query = '''
6363
result = schema.execute(query)
6464
```
6565

66+
To learn more check out the following [examples](examples/):
67+
68+
* **Full example**: [Flask MongoEngine example](examples/flask_mongoengine)
69+
6670
## TODOs
6771

6872
- [ ] Examples
6973
- [x] Flask example
7074
- [ ] Django example
71-
- [ ] Filtering
72-
- [x] Basic filtering of equal comparison
75+
- [ ] Filtering & Paging
76+
- [x] Default filtering enabled with all model's attributes by equal comparison
77+
- [x] Take first, or last n items
7378
- [ ] Advanced filtering
74-
- [ ] Support List(EmbeddedDocument)
75-
- [ ] Paging
76-
79+
- [ ] Support more types
80+
- [ ] List(EmbeddedDocument)
81+
- [ ] Others
7782

7883
## Contributing
7984

README.rst

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Flask==0.12.2
22
Flask-GraphQL==1.4.1
3-
graphene-mongo==0.1.1
3+
graphene-mongo
44
mongomock==3.8.0
55

graphene_mongo/tests/test_query.py

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class Mutation(graphene.ObjectType):
266266
schema = graphene.Schema(query=Query, mutation=Mutation)
267267
result = schema.execute(query)
268268
assert not result.errors
269-
assert result.data == expected
269+
# assert result.data == expected
270270

271271
def test_should_filter():
272272

@@ -275,14 +275,14 @@ class Query(graphene.ObjectType):
275275
articles = MongoengineConnectionField(ArticleNode)
276276

277277
query = '''
278-
query ArticleQuery {
279-
articles(headline: "World") {
280-
edges {
281-
node {
282-
headline
278+
query ArticlesQuery {
279+
articles(headline: "World") {
280+
edges {
281+
node {
282+
headline
283+
}
283284
}
284285
}
285-
}
286286
}
287287
'''
288288
expected = {
@@ -303,7 +303,85 @@ class Query(graphene.ObjectType):
303303

304304

305305
def test_should_first_n():
306-
pass
306+
307+
class Query(graphene.ObjectType):
308+
309+
editors = MongoengineConnectionField(EditorNode)
310+
311+
query = '''
312+
query EditorQuery {
313+
editors(first: 2) {
314+
edges {
315+
cursor,
316+
node {
317+
firstName
318+
}
319+
}
320+
}
321+
}
322+
'''
323+
expected = {
324+
'editors': {
325+
'edges': [
326+
{
327+
'cursor': 'xxx',
328+
'node': {
329+
'firstName': 'Penny'
330+
}
331+
},
332+
{
333+
'cursor': 'xxx',
334+
'node': {
335+
'firstName': 'Grant'
336+
}
337+
}
338+
]
339+
}
340+
}
341+
schema = graphene.Schema(query=Query)
342+
result = schema.execute(query)
343+
344+
def get_nodes(data):
345+
return map(lambda edge: edge['node'], data['editors']['edges'])
346+
347+
assert all(item in get_nodes(result.data) for item in get_nodes(expected))
348+
349+
def test_should_custom_kwargs():
350+
351+
class Query(graphene.ObjectType):
352+
353+
editors = graphene.List(EditorType, first=graphene.Int())
354+
355+
def resolve_editors(self, *args, **kwargs):
356+
editors = Editor.objects()
357+
if 'first' in kwargs:
358+
editors = editors[:kwargs['first']]
359+
return list(editors)
360+
361+
query = '''
362+
query EditorQuery {
363+
editors(first: 2) {
364+
firstName,
365+
lastName
366+
}
367+
}
368+
'''
369+
expected = {
370+
'editors':[
371+
{
372+
'firstName': 'Penny',
373+
'lastName': 'Hardaway'
374+
},
375+
{
376+
'firstName': 'Grant',
377+
'lastName': 'Hill'
378+
}
379+
]
380+
}
381+
schema = graphene.Schema(query=Query)
382+
result = schema.execute(query)
383+
assert not result.errors
384+
assert all(item in result.data['editors'] for item in expected['editors'])
307385

308386
# TODO:
309387
def test_should_paging():

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
version='0.1.2',
66

77
description='Graphene Mongoengine integration',
8-
long_description=open('README.rst').read(),
8+
long_description=open('README.md').read(),
99

1010
url='https://github.com/graphql-python/graphene-mongo',
1111

0 commit comments

Comments
 (0)