@@ -674,133 +674,165 @@ public function testFieldAliases()
674
674
public function provideFilterAndSortOnlyRead (): array
675
675
{
676
676
return [
677
- 'read with sort ' => [
678
- 'fixture ' => '_QuerySort ' ,
679
- 'query ' => <<<GRAPHQL
680
- query {
681
- readDataObjectFakes(sort: { author: { id: DESC }, myField: ASC }) {
682
- nodes {
683
- myField
684
- author {
685
- firstName
686
- }
687
- }
688
- }
689
- }
690
- GRAPHQL ,
691
- 'expected ' => [
692
- ["myField " => "test2 " , "author " => ["firstName " => "tester2 " ]],
693
- ["myField " => "test3 " , "author " => ["firstName " => "tester2 " ]],
694
- ["myField " => "test1 " , "author " => ["firstName " => "tester1 " ]],
677
+ 'read with sort ' => [
678
+ 'fixture ' => '_QuerySort ' ,
679
+ 'query ' => <<<GRAPHQL
680
+ query {
681
+ readDataObjectFakes(sort: { author: { id: DESC }, myField: ASC }) {
682
+ nodes {
683
+ myField
684
+ author {
685
+ firstName
686
+ }
687
+ }
688
+ }
689
+ }
690
+ GRAPHQL ,
691
+ 'args ' => [],
692
+ 'expected ' => [
693
+ ["myField " => "test2 " , "author " => ["firstName " => "tester2 " ]],
694
+ ["myField " => "test3 " , "author " => ["firstName " => "tester2 " ]],
695
+ ["myField " => "test1 " , "author " => ["firstName " => "tester1 " ]],
696
+ ],
695
697
],
696
- ],
697
- 'read with sorter files title DESC ' => [
698
- 'fixture ' => '_SortPlugin ' ,
699
- 'query ' => <<<GRAPHQL
700
- query {
701
- readDataObjectFakes(sort: { myField: ASC }) {
702
- nodes {
703
- myField
704
- files(sort: { title: DESC }) {
705
- title
706
- }
707
- }
708
- }
709
- }
710
- GRAPHQL ,
711
- 'expected ' => [
712
- ["myField " => "test1 " , "files " => [["title " => "file4 " ], ["title " => "file3 " ], ["title " => "file2 " ], ["title " => "file1 " ]]],
713
- ["myField " => "test2 " , "files " => []],
714
- ["myField " => "test3 " , "files " => []],
698
+ 'read with sorter files title DESC ' => [
699
+ 'fixture ' => '_SortPlugin ' ,
700
+ 'query ' => <<<GRAPHQL
701
+ query {
702
+ readDataObjectFakes(sort: { myField: ASC }) {
703
+ nodes {
704
+ myField
705
+ files(sort: { title: DESC }) {
706
+ title
707
+ }
708
+ }
709
+ }
710
+ }
711
+ GRAPHQL ,
712
+ 'args ' => [],
713
+ 'expected ' => [
714
+ ["myField " => "test1 " , "files " => [["title " => "file4 " ], ["title " => "file3 " ], ["title " => "file2 " ], ["title " => "file1 " ]]],
715
+ ["myField " => "test2 " , "files " => []],
716
+ ["myField " => "test3 " , "files " => []],
717
+ ],
715
718
],
716
- ],
717
- 'read with sorter files ParentID ACS, name DESC ' => [
718
- 'fixture ' => '_SortPlugin ' ,
719
- 'query ' => <<<GRAPHQL
720
- query {
721
- readDataObjectFakes(sort: { myField: ASC }) {
722
- nodes {
723
- myField
724
- files(sort: { ParentID: ASC, name: DESC }) {
725
- title
726
- }
727
- }
728
- }
729
- }
730
- GRAPHQL ,
731
- 'expected ' => [
732
- ["myField " => "test1 " , "files " => [["title " => "file2 " ],["title " => "file1 " ], ["title " => "file4 " ],["title " => "file3 " ]]],
733
- ["myField " => "test2 " , "files " => []],
734
- ["myField " => "test3 " , "files " => []],
719
+ 'read with sorter files ParentID ACS, name DESC ' => [
720
+ 'fixture ' => '_SortPlugin ' ,
721
+ 'query ' => <<<GRAPHQL
722
+ query {
723
+ readDataObjectFakes(sort: { myField: ASC }) {
724
+ nodes {
725
+ myField
726
+ files(sort: { ParentID: ASC, name: DESC }) {
727
+ title
728
+ }
729
+ }
730
+ }
731
+ }
732
+ GRAPHQL ,
733
+ 'args ' => [],
734
+ 'expected ' => [
735
+ ["myField " => "test1 " , "files " => [["title " => "file2 " ], ["title " => "file1 " ], ["title " => "file4 " ], ["title " => "file3 " ]]],
736
+ ["myField " => "test2 " , "files " => []],
737
+ ["myField " => "test3 " , "files " => []],
738
+ ],
735
739
],
736
- ],
737
- 'read with sorter files ParentID DESC, name ASC ' => [
738
- 'fixture ' => '_SortPlugin ' ,
739
- 'query ' => <<<GRAPHQL
740
- query {
741
- readDataObjectFakes(sort: { myField: ASC }) {
742
- nodes {
743
- myField
744
- files(sort: { ParentID: DESC, name: ASC }) {
745
- title
746
- }
747
- }
748
- }
749
- }
750
- GRAPHQL ,
751
- 'expected ' => [
752
- ["myField " => "test1 " , "files " => [["title " => "file3 " ],["title " => "file4 " ], ["title " => "file1 " ],["title " => "file2 " ]]],
753
- ["myField " => "test2 " , "files " => []],
754
- ["myField " => "test3 " , "files " => []],
740
+ 'read with sorter files ParentID DESC, name ASC ' => [
741
+ 'fixture ' => '_SortPlugin ' ,
742
+ 'query ' => <<<GRAPHQL
743
+ query {
744
+ readDataObjectFakes(sort: { myField: ASC }) {
745
+ nodes {
746
+ myField
747
+ files(sort: { ParentID: DESC, name: ASC }) {
748
+ title
749
+ }
750
+ }
751
+ }
752
+ }
753
+ GRAPHQL ,
754
+ 'args ' => [],
755
+ 'expected ' => [
756
+ ["myField " => "test1 " , "files " => [["title " => "file3 " ], ["title " => "file4 " ], ["title " => "file1 " ], ["title " => "file2 " ]]],
757
+ ["myField " => "test2 " , "files " => []],
758
+ ["myField " => "test3 " , "files " => []],
759
+ ],
755
760
],
756
- ],
757
- 'read with sorter files name ASC, ParentID DESC ' => [
758
- 'fixture ' => '_SortPlugin ' ,
759
- 'query ' => <<<GRAPHQL
760
- query {
761
- readDataObjectFakes(sort: { myField: ASC }) {
762
- nodes {
763
- myField
764
- files(sort: { name: ASC, ParentID: DESC }) {
765
- title
766
- }
767
- }
768
- }
769
- }
770
- GRAPHQL ,
771
- 'expected ' => [
772
- ["myField " => "test1 " , "files " => [["title " => "file3 " ],["title " => "file1 " ], ["title " => "file4 " ],["title " => "file2 " ]]],
773
- ["myField " => "test2 " , "files " => []],
774
- ["myField " => "test3 " , "files " => []],
761
+ 'read with sorter files name ASC, ParentID DESC ' => [
762
+ 'fixture ' => '_SortPlugin ' ,
763
+ 'query ' => <<<GRAPHQL
764
+ query {
765
+ readDataObjectFakes(sort: { myField: ASC }) {
766
+ nodes {
767
+ myField
768
+ files(sort: { name: ASC, ParentID: DESC }) {
769
+ title
770
+ }
771
+ }
772
+ }
773
+ }
774
+ GRAPHQL ,
775
+ 'args ' => [],
776
+ 'expected ' => [
777
+ ["myField " => "test1 " , "files " => [["title " => "file3 " ], ["title " => "file1 " ], ["title " => "file4 " ], ["title " => "file2 " ]]],
778
+ ["myField " => "test2 " , "files " => []],
779
+ ["myField " => "test3 " , "files " => []],
780
+ ],
775
781
],
776
- ],
777
- 'read with sorter files name DESC, ParentID ASC ' => [
778
- 'fixture ' => '_SortPlugin ' ,
779
- 'query ' => <<<GRAPHQL
780
- query {
781
- readDataObjectFakes(sort: { myField: ASC }) {
782
- nodes {
783
- myField
784
- files(sort: { name: DESC, ParentID: ASC }) {
785
- title
786
- }
787
- }
788
- }
789
- }
790
- GRAPHQL ,
791
- 'expected ' => [
792
- ["myField " => "test1 " , "files " => [["title " => "file2 " ],[ "title " => "file4 " ],["title " => "file1 " ],["title " => "file3 " ]]],
793
- ["myField " => "test2 " , "files " => []],
794
- ["myField " => "test3 " , "files " => []],
782
+ 'read with sort - with named sort arg ' => [
783
+ 'fixture ' => '_QuerySort ' ,
784
+ 'query ' => <<<GRAPHQL
785
+ query ( \$sort: DataObjectFakeSortFields) {
786
+ readDataObjectFakes(sort: \$sort) {
787
+ nodes {
788
+ myField
789
+ author {
790
+ firstName
791
+ }
792
+ }
793
+ }
794
+ }
795
+ GRAPHQL ,
796
+ 'args ' => [
797
+ 'sort ' => ['author ' => ['id ' => 'DESC ' ], 'myField ' => 'ASC ' ]
798
+ ],
799
+ 'expected ' => [
800
+ ["myField " => "test2 " , "author " => ["firstName " => "tester2 " ]],
801
+ ["myField " => "test3 " , "author " => ["firstName " => "tester2 " ]],
802
+ ["myField " => "test1 " , "author " => ["firstName " => "tester1 " ]],
803
+ ],
804
+ ],
805
+ 'read with sorter files ParentID DESC, name ASC - with named sort args ' => [
806
+ 'fixture ' => '_SortPlugin ' ,
807
+ 'query ' => <<<GRAPHQL
808
+ query ( \$sort: DataObjectFakeSortFields, \$fileSort: FilesSimpleSortFields) {
809
+ readDataObjectFakes(sort: \$sort) {
810
+ nodes {
811
+ myField
812
+ files(sort: \$fileSort) {
813
+ title
814
+ }
815
+ }
816
+ }
817
+ }
818
+ GRAPHQL ,
819
+ 'args ' => [
820
+ 'sort ' => ['myField ' => 'ASC ' ],
821
+ 'fileSort ' => ['ParentID ' => 'DESC ' , 'name ' => 'ASC ' ],
822
+ ],
823
+ 'expected ' => [
824
+ ["myField " => "test1 " , "files " => [["title " => "file2 " ], ["title " => "file4 " ], ["title " => "file1 " ], ["title " => "file3 " ]]],
825
+ ["myField " => "test2 " , "files " => []],
826
+ ["myField " => "test3 " , "files " => []],
827
+ ],
795
828
],
796
- ],
797
829
];
798
830
}
799
831
800
832
/**
801
833
* @dataProvider provideFilterAndSortOnlyRead
802
834
*/
803
- public function testFilterAndSortOnlyRead (string $ fixture , string $ query , array $ expected )
835
+ public function testFilterAndSortOnlyRead (string $ fixture , string $ query , array $ args , array $ expected )
804
836
{
805
837
$ author = Member::create (['FirstName ' => 'tester1 ' ]);
806
838
$ author ->write ();
@@ -841,7 +873,7 @@ public function testFilterAndSortOnlyRead(string $fixture, string $query, array
841
873
$ factory = new TestSchemaBuilder (['_ ' . __FUNCTION__ . $ fixture ]);
842
874
$ schema = $ this ->createSchema ($ factory );
843
875
844
- $ result = $ this ->querySchema ($ schema , $ query );
876
+ $ result = $ this ->querySchema ($ schema , $ query, $ args );
845
877
$ this ->assertSuccess ($ result );
846
878
$ records = $ result ['data ' ]['readDataObjectFakes ' ]['nodes ' ] ?? [];
847
879
$ this ->assertResults ($ expected , $ records );
0 commit comments