@@ -19,13 +19,15 @@ public QuerySet(
19
19
_jsonApiContext = jsonApiContext ;
20
20
PageQuery = new PageQuery ( ) ;
21
21
Filters = new List < FilterQuery > ( ) ;
22
+ Fields = new List < string > ( ) ;
22
23
BuildQuerySet ( query ) ;
23
24
}
24
25
25
26
public List < FilterQuery > Filters { get ; set ; }
26
27
public PageQuery PageQuery { get ; set ; }
27
28
public List < SortQuery > SortParameters { get ; set ; }
28
29
public List < string > IncludedRelationships { get ; set ; }
30
+ public List < string > Fields { get ; set ; }
29
31
30
32
private void BuildQuerySet ( IQueryCollection query )
31
33
{
@@ -55,6 +57,12 @@ private void BuildQuerySet(IQueryCollection query)
55
57
continue ;
56
58
}
57
59
60
+ if ( pair . Key . StartsWith ( "fields" ) )
61
+ {
62
+ Fields = ParseFieldsQuery ( pair . Key , pair . Value ) ;
63
+ continue ;
64
+ }
65
+
58
66
throw new JsonApiException ( "400" , $ "{ pair } is not a valid query.") ;
59
67
}
60
68
}
@@ -160,6 +168,29 @@ private List<string> ParseIncludedRelationships(string value)
160
168
. ToList ( ) ;
161
169
}
162
170
171
+ private List < string > ParseFieldsQuery ( string key , string value )
172
+ {
173
+ // expected: fields[TYPE]=prop1,prop2
174
+ var typeName = key . Split ( '[' , ']' ) [ 1 ] ;
175
+
176
+ var includedFields = new List < string > { "Id" } ;
177
+
178
+ if ( typeName != _jsonApiContext . RequestEntity . EntityName . Dasherize ( ) )
179
+ return includedFields ;
180
+
181
+ var fields = value . Split ( ',' ) ;
182
+ foreach ( var field in fields )
183
+ {
184
+ var internalAttrName = _jsonApiContext . RequestEntity
185
+ . Attributes
186
+ . SingleOrDefault ( attr => attr . PublicAttributeName == field )
187
+ . InternalAttributeName ;
188
+ includedFields . Add ( internalAttrName ) ;
189
+ }
190
+
191
+ return includedFields ;
192
+ }
193
+
163
194
private AttrAttribute GetAttribute ( string propertyName )
164
195
{
165
196
return _jsonApiContext . RequestEntity . Attributes
0 commit comments