@@ -606,6 +606,53 @@ class Query(graphene.ObjectType):
606
606
graphene_settings .RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
607
607
608
608
609
+ def test_should_error_if_last_is_greater_than_max ():
610
+ graphene_settings .RELAY_CONNECTION_MAX_LIMIT = 100
611
+
612
+ class ReporterType (DjangoObjectType ):
613
+
614
+ class Meta :
615
+ model = Reporter
616
+ interfaces = (Node , )
617
+
618
+ class Query (graphene .ObjectType ):
619
+ all_reporters = DjangoConnectionField (ReporterType )
620
+
621
+ r = Reporter .objects .create (
622
+ first_name = 'John' ,
623
+ last_name = 'Doe' ,
624
+
625
+ a_choice = 1
626
+ )
627
+
628
+ schema = graphene .Schema (query = Query )
629
+ query = '''
630
+ query NodeFilteringQuery {
631
+ allReporters(last: 101) {
632
+ edges {
633
+ node {
634
+ id
635
+ }
636
+ }
637
+ }
638
+ }
639
+ '''
640
+
641
+ expected = {
642
+ 'allReporters' : None
643
+ }
644
+
645
+ result = schema .execute (query )
646
+ assert len (result .errors ) == 1
647
+ assert str (result .errors [0 ]) == (
648
+ 'Requesting 101 records on the `allReporters` connection '
649
+ 'exceeds the `last` limit of 100 records.'
650
+ )
651
+ assert result .data == expected
652
+
653
+ graphene_settings .RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
654
+
655
+
609
656
def test_should_query_promise_connectionfields ():
610
657
from promise import Promise
611
658
@@ -620,7 +667,7 @@ class Query(graphene.ObjectType):
620
667
621
668
def resolve_all_reporters (self , info , ** args ):
622
669
return Promise .resolve ([Reporter (id = 1 )])
623
-
670
+
624
671
schema = graphene .Schema (query = Query )
625
672
query = '''
626
673
query ReporterPromiseConnectionQuery {
@@ -648,6 +695,109 @@ def resolve_all_reporters(self, info, **args):
648
695
assert not result .errors
649
696
assert result .data == expected
650
697
698
+ def test_should_query_connectionfields_with_last ():
699
+
700
+ r = Reporter .objects .create (
701
+ first_name = 'John' ,
702
+ last_name = 'Doe' ,
703
+
704
+ a_choice = 1
705
+ )
706
+
707
+ class ReporterType (DjangoObjectType ):
708
+
709
+ class Meta :
710
+ model = Reporter
711
+ interfaces = (Node , )
712
+
713
+ class Query (graphene .ObjectType ):
714
+ all_reporters = DjangoConnectionField (ReporterType )
715
+
716
+ def resolve_all_reporters (self , info , ** args ):
717
+ return Reporter .objects .all ()
718
+
719
+ schema = graphene .Schema (query = Query )
720
+ query = '''
721
+ query ReporterLastQuery {
722
+ allReporters(last: 1) {
723
+ edges {
724
+ node {
725
+ id
726
+ }
727
+ }
728
+ }
729
+ }
730
+ '''
731
+
732
+ expected = {
733
+ 'allReporters' : {
734
+ 'edges' : [{
735
+ 'node' : {
736
+ 'id' : 'UmVwb3J0ZXJUeXBlOjE='
737
+ }
738
+ }]
739
+ }
740
+ }
741
+
742
+ result = schema .execute (query )
743
+ assert not result .errors
744
+ assert result .data == expected
745
+
746
+ def test_should_query_connectionfields_with_manager ():
747
+
748
+ r = Reporter .objects .create (
749
+ first_name = 'John' ,
750
+ last_name = 'Doe' ,
751
+
752
+ a_choice = 1
753
+ )
754
+
755
+ r = Reporter .objects .create (
756
+ first_name = 'John' ,
757
+ last_name = 'NotDoe' ,
758
+
759
+ a_choice = 1
760
+ )
761
+
762
+ class ReporterType (DjangoObjectType ):
763
+
764
+ class Meta :
765
+ model = Reporter
766
+ interfaces = (Node , )
767
+
768
+ class Query (graphene .ObjectType ):
769
+ all_reporters = DjangoConnectionField (ReporterType , on = 'doe_objects' )
770
+
771
+ def resolve_all_reporters (self , info , ** args ):
772
+ return Reporter .objects .all ()
773
+
774
+ schema = graphene .Schema (query = Query )
775
+ query = '''
776
+ query ReporterLastQuery {
777
+ allReporters(first: 2) {
778
+ edges {
779
+ node {
780
+ id
781
+ }
782
+ }
783
+ }
784
+ }
785
+ '''
786
+
787
+ expected = {
788
+ 'allReporters' : {
789
+ 'edges' : [{
790
+ 'node' : {
791
+ 'id' : 'UmVwb3J0ZXJUeXBlOjE='
792
+ }
793
+ }]
794
+ }
795
+ }
796
+
797
+ result = schema .execute (query )
798
+ assert not result .errors
799
+ assert result .data == expected
800
+
651
801
652
802
def test_should_query_dataloader_fields ():
653
803
from promise import Promise
0 commit comments