File tree Expand file tree Collapse file tree 2 files changed +67
-1
lines changed 
test/Field/Page/Fieldtype/FieldtypeOptions Expand file tree Collapse file tree 2 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 99use  ProcessWire \GraphQL \Utils ;
1010use  ProcessWire \GraphQL \Type \Fieldtype \Traits \SetValueTrait ;
1111use  ProcessWire \GraphQL \Type \Fieldtype \Traits \FieldTrait ;
12+ use  ProcessWire \Page ;
1213
1314class  FieldtypeOptions
14- {  
15+ {
1516  use  FieldTrait;
1617  use  SetValueTrait;
1718
@@ -63,6 +64,34 @@ public static function type($field)
6364    return  $ type
6465  }
6566
67+   public  static  function  field ($ field
68+   {
69+     return  Cache::field ($ fieldname , function  () use  ($ field
70+       // description 
71+       $ desc$ fielddescription ;
72+       if  (!$ desc
73+         $ desc"Field with the type of  {$ fieldtype }" ;
74+       }
75+ 
76+       return  [
77+         'name '  => $ fieldname ,
78+         'description '  => $ desc
79+         'type '  => self ::type ($ field
80+         'resolve '  => function  (Page $ pagearray  $ argsuse  ($ field
81+           $ fieldName$ fieldname ;
82+ 
83+           // If a single option field does not have an id, then it means it's empty. 
84+           if  (!self ::isMultiple ($ field$ page$ fieldNameid ) {
85+             return  null ;
86+           }
87+ 
88+           return  $ page$ fieldName
89+         }
90+       ];
91+     });
92+   }
93+ 
94+ 
6695  public  static  function  inputType ($ field
6796  {
6897    return  Cache::type (self ::getName ($ fieldfunction  () use  ($ field
Original file line number Diff line number Diff line change 1+ <?php 
2+ 
3+ /** 
4+  * Empty options field should return null. 
5+  */ 
6+ 
7+ namespace  ProcessWire \GraphQL \Test \FieldtypeOptions ;
8+ 
9+ use  ProcessWire \GraphQL \Utils ;
10+ use  ProcessWire \GraphQL \Test \GraphQLTestCase ;
11+ 
12+ class  CaseFiveTest extends  GraphQLTestCase
13+ {
14+   const  settings  = [
15+     "login "  => "admin " ,
16+     "legalTemplates "  => ["city " ],
17+     "legalFields "  => ["options_single " ],
18+   ];
19+ 
20+   public  function  testValue ()
21+   {
22+     $ citypages ()->get ("template=city, options_single='' " );
23+     $ query"{  
24+       city (s:  \"id= $ cityid \") { 
25+         list { 
26+           options_single { 
27+             title 
28+             value 
29+             id 
30+           } 
31+         } 
32+       } 
33+     } "
34+     $ resself ::execute ($ query
35+     self ::assertNull ($ resdata ->city ->list [0 ]->options_single , "Empty option field should return null. " );
36+   }
37+ }
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments